Well! You CAN Learn Something New Every Day!
I just solved the Sphere Online Judge’s “Enormous Input” test. It’s only a tutorial test, so it should have been easy. And it WOULD have been, if I had known a bit more about the merits of the iostream and stdio.h methods of reading and writing data.
The test itself is pretty basic:
The purpose of this problem is to verify whether the method you are using to read input data is sufficiently fast to handle problems branded with the enormous Input/Output warning. You are expected to be able to process at least 2.5MB of input data per second at runtime.
The input begins with two positive integers n k (n, k<=10^7). The next n lines of input contain one positive integer ti, not greater than 10^9, each.
Write a single integer to output, denoting how many integers ti are divisible by k.
I started off using iostream data input and output. It didn’t work. I tried saving computation time by writing to an array before computing and later to a vector, both with no luck. Then reviewing a different problem, I read this:
Guys, even if any of those hideous solutions work, which is a lot to say for the very first and easiest problem ever to exist, they will land you a time of 0.01.
The I/Ostream library is SLOW as hell – depending on what you read/write to the stream, they are at LEAST 10 times slower than the standart reading/writing functions in stdio. Use stdio.h.
And I had my solution! I went back to my first solution, put in include , substituted scanf and printf for cin and cout and submitted my code. And it worked!
Here is what I submitted:
int count = 0;
for (int i = 0;i<n;i++)
clean, simple and most importantly, successful! I’m happy!