I have been trying to identify where is my code using most of the allocated 500ms using time.time() at different places in the python code.
I find out that the input processing takes ages, especially the first time input() is called. Meaning the single line resources = int(input)) takes more than 300 ms.
start_time_inputs = start_time_inputs = time.time()
resources.resources = int(input())
print(“inputs resources — %s seconds —” % (time.time() - start_time_inputs), file=sys.stderr, flush=True)
Prints “inputs resources — 0.34633588790893555 seconds —”
Am I the only one with this issue? Shouldn’t the waiting of the input be outside of the 500ms window for our code to give an answer?
The input data isn’t available when your program launches - the server needs time to prepare it (on the first turn) or process your output (on later turns). The timer on the server side doesn’t start until after it has sent you the input so you shouldn’t start measuring time until after you’ve read the first line each turn.
1 Like
I agree that it should be like this, although I always get a time out when the total time passes 0.5s, and this is with a timer starting before the first input is red.
Thus my post.
I’m having issues with timeouts when trying to assign the input to variables, more specifically when trying to assign the last input of a kind (eg new buildings) to variables. Is this a bug or is it meant to be this way? The code I’m using (a list comprehension) was even in the code to start with! But I figured out that it’s the last one (out of three) that makes it time out. Either something is special about the last one, or it simply gets to 1000 ms when assigning the third input. (Yes, this happens already on the first round)
I’m enjoying the problem-solving, but this makes it a bit frustrating… Please help.
Sometimes it take even up to 3.5 s (!) before first input.
But as @RoboStac wrote, counting time from moment after first input work quite okay.
Check, if it is faster with with stdin and stdout instead of input():