Following is a complete question I copied from a site
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<=107). The next n lines of input contain one positive integer ti, not greater than 109, each.
Write a single integer to output, denoting how many integers ti are divisible by k.
OK. For the question these are the restrictions
Time limit: 8s
Source limit: 50000
And the following is my code
Whenever I run this code in that site, it says "Time Limit Exceeded". Is there is a way to reduce the performance time and get rid of that problem? Please help..
Are you better than me? Then please show me my mistakes..
Yohan Weerasinghe wrote:Whenever I run this code in that site, it says "Time Limit Exceeded". Is there is a way to reduce the performance time and get rid of that problem? Please help..
Well personally, I like your choice of a BufferedReader and readLine() for reading the lines; I suspect it's quite a bit quicker than Scanner.
And you certainly don't need to scan the String: I'd use String.split() for the header and a simple Integer.parseInt() for your 'ti' lines.
Isn't it funny how there's always time and money enough to do it WRONG?
Artlicles by Winston can be found here
Hi guys, Thanks a lot for all of your replies. I didn't get any email notification for this thread, that is why I got late to reply. I will check your suggestions, meanwhile, I am talking about this problem