CodeChef Newbie: Why is my submission failing?



Hi All,

I am new here, though not new to Java, please be kind. I am trying to make submission to a problem using Java. The code runs standalone fine in 0.4 seconds. But when I submit it I am told it is taking in excess of 0.12 seconds. I am not sure what tests are run on it as test data is not visible. Any idea what am I doing wrong here?

Any help would be appreciated.

Thanks & Regards.


It seems like your submission is that of an ongoing contest(Your link states 403 access denied!).

The verdict you are getting is TLE(Time Limit Exceeded). The 0.12 sec’s doesn’t imply it took just 0.12 seconds more. The judge stops the execution of your program when it crosses the time limit specified. The only thing you could do is change/modify the logic/algorithm you used so that the code can run successfully in the given time limit.
Also, please don’t post back the code on this forum since the question is from an ongoing contest! :smile:


Thanks. My question was more on (1) how do I know what is the issue and (2) how to replicate using the same test cases that the auto evaluator uses. When the program takes just 0.4 seconds on the online IDE, why should it take longer when submitted is something that I have no clue about. The code also runs fine offline.


If I would give you to 5 random numbers to add(on paper) you’d tell me the answer in a minute. But what if i gave you 10^5 random numbers and ask you to add them(on paper) ? You would take a lot of time(if not forever) to find the answer.

Similarly connect this to your code. It takes 0.4 sec for a small input. How long would it then take if a larger input was given to it?

However, if I gave you 10^5 numbers in a pattern(1, 2, 3, 4, ...), you would have been easily able to solve it using a better logic than just adding all the numbers one after the other.

Your code functions in a similar way. There is a better logic to solve the problem, but you are still trying the naive way. The questions are all about finding the most optimal solution.