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.
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
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):- CHEFKEY Problem - CodeChef
My solution:- https://github.com/ishaan123/CodeChef/blob/master/codechef-2.cpp
#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??
#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;
}
y i m getting TLE in my code can anyone help
[1]
please help
[Problem set][2]
[1]: https://www.codechef.com/viewsolution/17096612
[2]: https://www.codechef.com/FLMOCK02/problems/STACKS/
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.
I don’t know which problem you are trying to solve. Please provide problem code and a link to your solution. Don’t post code here. It’s unreadable.
Try removing cin and cout and use printf and scanf instead. This might work. Otherwise your code might have higher complexity. You need to optimize a bit
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.
Why do i get time limit error
t=int(input())
while(t>0):
t=t-1
m,n=map(int,input().split())
if m==1:
m=2
for i in range(m,n+1):
c=0
for j in range(2,i//2+1):
if (i%j==0):
c=1
break
if(c<=0):
print(i)
print()
I’m unable to solve TLE issue in my code.Please guide me.
Question Link:PRIME1 Problem - CodeChef
Learn other method method to find primes - seive of ertoshthenis.
And also learn about time complexity and time limits.
Thanks for guiding:)
Can someone send the link for Enormous Input Test problem
#include
#include<stdio.h>
using namespace std;
int main() {
int t=0;
scanf("%d",&t);
while(t–)
{
unsigned long long n=0,c=0;
scanf("%u",&n);
for(unsigned long long i=1;i<=n;i++)
{
if(i%2==0)
{
if(n%2==0)
{
i=i/2;n=n/2;
}
else
c++;
}
}
printf("%u",c);
printf("\n");
}
return 0;
}
why i am gey
ting tle
def adjacentElementsProduct(arr):
p=0
for i in range(len(arr)) :
if i+1 < len(arr) :
if arr[i]*arr[i+1] > p:
p=arr[i]*arr[i+1]
return p
arr= list(map(int,input().split()))
adjacentElementsProduct(arr)
showing TLE what is the solution
please post question link.
is it a ongoing contest, it shows me “not authorised” error ?
not a contest it is a site similar to hackerrank “codesignal” is its name.
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
Example
For inputArray = [3, 6, -2, -5, 7, 3]
, the output should be
adjacentElementsProduct(inputArray) = 21
.
7
and 3
produce the largest product.
this is the question