Q:

How is time limit calculated on codechef ?

In the march challenge of codechef, java solutions for the problem "Random Decreasing Function" have been accepted that take more than 30 seconds but the given time limit is 2 seconds. This is well over 2X time(4 seconds) allowed for java .

A:

Time limit specified is only for 1 test file, there are many test files and the final time on your submission is the total time taken to pass all the test files.  
Quoting from the Codechef FAQ page -:   [ http://www.codechef.com/wiki/faq ]  

What does the execution time displayed for my submission mean?
Codechef might test your code multiple times with different input
  files. If your code gives the correct answer within the time limit for
  each input file, the execution time displayed is the total of the time
  spent for each test case.
If your code does not pass an input file correctly, the time limit
  will be the total time of all input files, up to and including the one
  on which you fail, but not any further ones.
An example: suppose there are 5 input files, each with a time limit of
  2 seconds. Your program runs for 1 second on each input file and
  produces the correct answer. The total time displayed will be 5
  seconds - which is fine, because the time limit only applies to each
  input file individually.
On the other hand, suppose you get the first 2 input files correct in
  1 second, the third one incorrect in 1.5 seconds. Your reported time
  will be 3.5 seconds.
People are often confused by a wrong answer in a very quick time
  changing to time limit exceeded. This is due to the first input file
  being small; a wrong answer means the time for large input files is
  not included.

