×

# Why do I get a Time Limit Exceeded?

 1 1 Why my program keeps getting Time Limit Exceeded? What are some of the reasons of getting TLE? asked 20 Mar '13, 16:22 560●10●19●24 accept rate: 42%

 2 To understand Time Limit Exceeded(TLE), understanding how the online judge works will help. The online judge allocates resources like memory and CPU for evaluating every submission. However, to ensure that your submission does not keep running for an infinite time, the online judge has to stop your submission from running after a particular time period. This time period is actually decided by the problem setter and is given as one of the inputs to the online judge. Once the submission program runs for time period the judge system issues a system kill command to the program execution and assigns TLE result to the submission. The most common reason that you would get a TLE is because your program is too slow. If a problem tells you that N <= 100000, and your program has nested loops each which go up to N, your program will never be fast enough. Read the bounds in the input carefully before writing your program, and try to figure out which inputs will cause your program to run the slowest. The second most common cause of TLE is that your method of reading input and writing output is too slow. In Java, do not use a Scanner; use a BufferedReader instead. In C++, do not use cin/cout - use scanf and printf instead. In Python, you could try speeding up your solutions by adding the following two lines to the start of your file: import psyco psyco.full()  To see if your method of reading input is fast enough, try solving the Enormous Input Test problem. If you get time limit exceeded, try another method of reading input. Finally, you may have tested your code on all sorts of large inputs and are sure your code will run inside the time limit. However, CodeChef's judge may be slower than your computer. It is common for a program to take 2-3 times as long on CodeChef as it does on your computer. The time limits are all attainable(tested by our problem tester), so you will just need to come up with a way of making your algorithm answered 20 Mar '13, 16:26 0★admin ♦♦ 17.6k●347●489●517 accept rate: 36% 4 From the above answer it should be clear to everyone, that when you got time for example 1.01s when timelimit was 1 seconds it doesn't mean your program finished in 1.01 but was killed = judge is not waiting. (13 Nov '14, 17:12)
 1 @dragonemperor @betlista @admin how to input a string whose number of characters we do not know using scanf in c++ ?? answered 30 Mar '16, 19:54 19●1●3 accept rate: 0% Hey @rajvir007 here is the solution to your question which I posted in discuss as a new question https://discuss.codechef.com/questions/80575/input-string-in-c More over I have upvoted your question so that you can now ask question on your own and upvote and participate in codechef discuss and community rather that posting questions in answer column of editorials. (31 Mar '16, 11:39) jain_mj3★
 0 #include using namespace std;  int z(int n) { int f=5; int a[100000]; int i=0,c=0; while((n/5)>0) { a[i]=n/f; c=c+a[i]; i++; f=f*5; } return c;  } int main() { int t,n,i; cin>>t; int k[t]; for(i=0;i>n; k[i]=z(n); } for(i=0;i
 0 It means the program you are using is doing more computations than expected. Usually, loops that goes upto 10^6-10^7 are acceptable with 1-2s time limit. It usually depends on the problem. answered 26 Oct '15, 23:43 21●2 accept rate: 0%
 0 Implementation of wrong or way of use(algorithm) data structure . answered 27 Oct '15, 13:17 58●1●5 accept rate: 8%
 0 can anybody tell me what is the problem in my code i am getting TLE erroe when submitted. http://code.geeksforgeeks.org/eNfy3Q answered 29 Oct '15, 18:07 1 accept rate: 0%
 0 1 . High Complexity. 2. Sometimes due to IO functions. Try to use Fast IO or optimize your code as much as possible. answered 06 Apr '16, 11:22 438●11 accept rate: 16%

# include<stdio.h>

long int prod(long int ar[],long int x){ long int p,s=0; if(x==1)return ar[0]; else if(x==2)return ar[1]*ar[0]+ar[1]+ar[0]; else { for(p=2;p<x;p++)s=ar[p]*(1+prod(ar,x-1))+prod(ar,x-1);} return="" s;="" }="" int="" magic(long="" int="" n){="" long="" int="" c="1,nn,i=0,p,q=n,j,k,s=0,ar[10000];" nn="0;p=n;" while(p="">0){p=p/10;nn++;} long int a[nn];while(n>0){a[i]=n%10;i++;n=n/10;} s=prod(a,nn); if(s%2==0)return 1; else return 0;

}

int main(){ long int n,c,i,t,j,k; scanf("%ld",&t); for(j=0;j<t;j++){k=1; scanf("%ld",&i);n=0; while(k<=i){ if(magic(n)==1)k++;n++; }

printf("%ld\n",n-1);


} } //This is my code for chef hiring problem(code-CHEARMY).why am i getting TLE in codechef? but it is running successfully in my computer.

1
accept rate: 0%

 0 how to avoid loop that goes upto 10^6 or 10^12? what is the alternative for it? answered 11 Jun '16, 15:49 1 accept rate: 0%

# include<stdio.h>

int main() { long int a[10000001],n,t,i,j; scanf("%d",&n); for(i=0;i<n;i++) {="" scanf("%d",&a[i]);="" }="" for(i="0;i&lt;n;i++)" {="" for(j="0;j&lt;(n-1);j++)" {="" if(a[j]="">a[j+1]) { t=a[j]; a[j]=a[j+1]; a[j+1]=t; } } } for(i=0;i<n;i++) { printf("%d",a[i]); } return 0; }

Can u please tell what's wrong in this I am getting time limit error. .


2★dragon96
283
accept rate: 20%

 0 guys, I have got 1 karma. please increase my karma(by liking) to 3,so that i could ask my doubts in the forum. Thanks in advance for spending your time. answered 03 Jul '16, 14:19 47●1●5 accept rate: 0%
 0 Your program may be so long that it takes more time in compiling than specified in question. Continously calling big loops are example of that.So think big and make your code small.Thank you answered 02 Oct '16, 01:14 1 accept rate: 0%
 0 Hey I am new to CodeChef and I am not comfortable with this time limit for execution. My all algorithms are logically correct and my program is working perfectly fine on my system but on codechef it is showing TLE error. Program name is Chef And Keyboard(CHEFKEY):- https://www.codechef.com/problems/CHEFKEY My solution:- https://github.com/ishaan123/CodeChef/blob/master/codechef-2.cpp answered 06 Nov '16, 15:28 1 accept rate: 0%

# include <stdio.h>

int main() { int i,t,c=d=e=f=0,g,h,N,X[N],Y[N]; scanf("%d",&t);

for(i=0;i<t;i++)
{
scanf("\n %d",&N);
for(i=0;i<N;i++)
{
scanf("%d",&X[i]);
}
for(i=0;i<N;i++)
{
scanf("%d",&Y[i]);
}
for(i=0;i<N;i++)
{
if(i%2==0)
{
c=c+X[i];
e=e+Y[i];
}
else{
d=d+X[i];
f=f+Y[i];
}
}
g=c+f;
h=d+e;
if(g<h){
printf("%d",g);
}
else
{
printf("%d \n",h);
}
}
return 0;
}


why do i get a timi limit error??

1
accept rate: 0%

# include<stdio.h>

int main() { int t,m[10],n[10],i,j,primes[10^7+1]; for(i=0;i<=10^7;i++) primes[i]=1; primes[0]=0; primes[1]=0; for(i=2;ii<=10^7;i++) { if(primes[i]==1) { for(j=2;ij<=10^7;j++) primes[i*j]=0; } } scanf("%d",&t); for(i=1;i<=t;i++) scanf("%d%d",&m[i],&n[i]); for(i=1;i<=t;i++) { for(j=m[i];j<=n[i];j++) { if(primes[j]==1) printf("%d\n",j); } printf("\n"); } return 0; }

1
accept rate: 0%

Why do i get time limit error

(11 Aug '17, 12:04)
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×607
×191

question asked: 20 Mar '13, 16:22

question was seen: 65,467 times

last updated: 11 Aug '17, 12:04