You are not logged in. Please login at to post your questions!


How does the time limit work

What is the time limit allowed for my code. What is the worst case time that my code can run on on the given test cases? Is the time limit different for different languages?

asked 21 Jun '12, 11:14

suraj_sharma's gravatar image

2★suraj_sharma ♦♦
accept rate: 0%

Time limit can be different for each problem. For example look at TEST problem, it's written there, that time limit is 3 seconds.

This time limit in meant so, that your code have to return correct value for one input file in the limit. Sometimes there is more than one test case in file, then the sum of times per test case have to be lower than time limit - for example in FCTRL problem file has 100.000 test cases and time limit for such file is 8 seconds.

Some languages are slower than others (especially I/O operations), so the time limit is multiplied by some consstant - it's described here.


answered 21 Jun '12, 11:34

betlista's gravatar image

3★betlista ♦♦
accept rate: 11%

Your program must read, process, and output the result for an input file within the specified time limit. An input file can contain a single test case or multiple test cases depending on the problem setter’s discretion. A test case will be of the format mentioned in the problem statement.

This means, if the input file contains multiple test cases, your code must complete ALL of these within time limit specified. If the time limit is 2 seconds, and there are 1000 test cases, your program shouldn't be taking 2 second per test case - it needs to run all 1000 cases in under 2 seconds.

There can be multiple input test files too, each containing single or multiple test cases. The time limit is applied to each test file. That means If the time limit is 2 seconds, and there are 5 test files, your program could take upto 10 seconds to execute - it needs to run all 5 test files in under 10 seconds. However, it is to be noted, that the number of test files is not mentioned anywhere and is agnostic to the user.

Some programming languages are slower than others, and are thus given more time. Currently, Java and Python are allowed twice the time limit, while Ruby, PHP and Lisp are allowed to run for up to three times the time limit.

The hyperlinked blog post explains how the time limit will work for various languages.


answered 21 Jun '12, 11:16

admin's gravatar image

0★admin ♦♦
accept rate: 35%

edited 27 Jul '15, 17:58

include<bits stdc++.h="">

using namespace std; int c; long long a; int main(void) { int t,x=0; long long b; cin>>t; while(x<t) {="" c="0;&lt;br"/> cin>>a; cin>>b; while(a!=b) { if(a%2==0) { if(a>b) { a=a/2; c++; } else { a=a2; c++; } } else { if(a==1) { a=a2; c++; } else { a=(a-1)/2; c++; } }

} x++; cout<<c<<endl; } }


answered 12 Oct '15, 08:35

rehaanhaider's gravatar image

accept rate: 0%

My program is running fine in codechef's IDE and is taking 1/40 th of the time limit to compile and execute. Yet when I'm trying to make a submission, I get a message saying, "Time limit exceeded".


answered 26 Jul '16, 11:07

shayakbanerjee's gravatar image

accept rate: 0%

include <stdio.h>

include <inttypes.h>

int i,b,n; int main (){

scanf("%d",&n); unsigned long long int temp[n],j;

for(i=0; i<n;i++){ scanf("%llu",&temp[i]);}

for(i=0; i<n;i++){
    b= 0;
for(j=temp[i]-1; j>1; j--){
    if((temp[i]%j) == 0){

} return 0; } i'm participating in codechef for first time. It is always showing time limit exceed


answered 08 Oct '17, 21:58

agnostics's gravatar image

accept rate: 0%

edited 08 Oct '17, 22:00

toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 21 Jun '12, 11:14

question was seen: 23,943 times

last updated: 08 Oct '17, 22:00