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?
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.
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.
#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;
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;
}
}
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”.
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){
b++;
if(b==2){break;}
}
}if(b==1){printf("YES\n");}
else{printf("NO\n");}
}
return 0;
}
i’m participating in codechef for first time.
It is always showing time limit exceed