This is one of the beefs I have with online judging systems like this..... it is not testing the algorithm, or anything like that. Instead, consider doing the very last line like:
// the longest value will be 11 chars long because % 1000000007 + "\n"" "
StringBuilder sb = new StringBuiderStringBuilder(N * 11);
for (long l : A) {
sb.append(l).append("\n"" ");
}
System.out.printlnprint(sb.toString());
A single println
is almost always N
times faster than N
println
s.
If that does not make it work in time, then consider reading the entire System.in in to a buffer, and parsing it from the buffer.