No, i don’t have this problem.
With the auto-generated code, reading the inputs only takes 5 milliseconds.
A few questions :
does it take 2 seconds every time ?
did you try to remove some parts of your code (like the creation of robot objects) to see if it affects the time ?
the timeout of the game is 1 second but your program is allowed to print something after 2 seconds ? (usually when you exceed 10-100 ms the local arena timeouts and no more logs are printed)
If there nothing wrong with the hidden code, your AI shouldn’t take this long.
did you try to remove some parts of your code (like the creation of robot objects) to see if it affects the time ?
No (I was so sure that It could not be my code ha ha) I’ll try to iteratively remove each piece of the code to find which one causes the issue.
Thank you.
class Player {
public static void main(String args[]) {
long start = System.nanoTime();
Scanner in = new Scanner(System.in);
for (int i = 0; i < 10; i++) {
String line = in.nextLine();
}
int robotCount = in.nextInt();
for (int i = 0; i < robotCount; i++) {
int x = in.nextInt();
int y = in.nextInt();
String direction = in.next();
}
System.err.println("time elapsed " + ((System.nanoTime() - start)/1000000) +"ms");
System.out.println("0 0 U 1 1 R 2 2 D 3 3 L");
}
}
I end up with the same issue on multiple test cases.
time elapsed 2191ms time elapsed 1784ms …
System.nanoTime() returns nanoseconds, so the above result should be valid.
It should print something like : time elapsed 2129ms time elapsed 6ms
CodinGame starts its timer after the first input has been read.
So, to have the right elapsed time, your code should be :
Scanner in = new Scanner(System.in);
long start = 0;
for (int i = 0; i < 10; i++) {
String line = in.nextLine();
if (i == 0) {
start = System.nanoTime();
}
}
PS : It explains why you were allowed to print something after 2s.
I didn’t see there was already an answer from @cg123