test my program locally for multiple test cases

thanks for your reply
but i want to know that if i am getting TLE in any submission than how much time it is taking actually for all the test cases and till what input it is working fine so that i can optimize it further.

sorry, but I really don’t understand your question

sorry that i am unable to express.
I was submitting a solution to a problem and it was showing time limit exceeded that means it is taking more time than mentioned in the problem statement.
i just want to know that how much time(in seconds) it is taking for all the input cases of codechef.
i hope that i am clear now.

Well if your algorithm is good enough it will work for all cases, you would be giving yourself much more work if you wanted to use this approach often, for the easy and medium problem I advise you to find an algorithm that works for the edge cases specially those with large inputs and that work on the constraints… For that as @michal27 said you should write an input generator and you have to make sure your reading and writing routines are fast enough, there are posts and pages here on codechef that cover that part, if you want to check for yourself just submit a solution to INTEST.

@nishant_25: I don’t think you need to know how much time it takes. If you had TLE, than there are two possibilities:

  1. Your solution is just slow from its concept - that can be verify by time complexity. As I mentioned, if you try submit O(n^2) solution with n=10^5 you never get it right with any optimization.

  2. Your idea is fast enough, you just implementid slowly. In this case there are several approaches you can try - check if your I/O is fast enough, if you don’t use double arithmetic instead integer etc.

1 Like

Well, this may not be a true. At least Slovak judge wait to max(2.time, time+2) where time is timelimit. And I don’t think that has no reason.

So sometimes it’s possible see, that my program run 1.2 seconds when timelimit is 1s. But probably codechef doesn’t support this feature.

I love such codes - you used fast read, but slow sorting O(n^2)… You have to use O(n * log(n) ) sorting :wink:

probably even O(n) counting sort. Checkout this question

yes that is exactly what i want to know somehow

yes the sorting(selection sort) i used is slow.
i am just giving an example.

Aaa, I see. You cannot find this information, because someone can print the result at the end instead of during the processing. Information about how many bytes were written to stdout is not available…

suppose i am having a O(nlogn) solution with n=10^5.
than how can i find time(in seconds) taken by solution for n=10^5 or for any other n. Is it possible

You cannot, as @michal27 wrote

you don’t know on which machine your program will be tested

can i find it for my own system or for my own machine?

@michal27 Your code ran for 1.2 seconds on a problem with 1 sec time limit, because, there were more than one test file, and the time reported is the total time taken. The time limit, however, is for individual test files.

can you please tell me that if my algorithm has complexity of O(n) and i am taking n=10^6 than it becomes O(10^6). what is the meaning of this. Or i can’t say like this?

see the table in this link - CompSci 101 - Big-O notation | Dave Perrett

It tries to describe how “bad” is O(n^2) to O(n).

How to say it simply, try this example. Let say you have program with O(n) complexity (linear) and for 1000 items it runs for 0.1s, when n is 100 times bigger, then your program will run 10 seconds.

If another program has O(n^2) complexity and it runs for n=1000 0.1s, for n 100 times bigger it runs 100^2=10.000 times longer so instead of 10 seconds as in O(n) it will run 1000 seconds = ~17 minutes.

@tijoforyou: I know, that was just example from Slovak judge.

As I say, you can use command time if you work under Linux. Otherwise I don’t know, but sure it’s possible. But that will give you just very rough estimation.

@betlista is it possible to find time for my own machine rather than for codechef machine so that i can have a rough estimation