1 / 15
Jun 2012

Not necessarily.

It means your submission exceed the time limit. That is all.

I AM GETTING MANY TLE'S. I GET CORRECT ANS ON MY COMPILER[DEV C++].
I USE C LANGUAGE.WHICH ONE SHOULD I USE ,WHICH IS FAST.

TLE has nothing to do with getting the correct answer. The reason for your TLE is likely poor analysis of the input constraints and therefore coming up with an algorithm with poor operational complexity (big oh).

Maybe if you posted the problem that you are working on, as well as your code, someone could help point out the issue

oh thank you for replying to my every post.........

this is for http://www.spoj.pl/problems/EASYMATH/2 getting TLE.this is the most simplest code i can think of.

include

int main()
{
long n,m,a,d,i;
int t,j;
scanf("%d",&t);
for(j=0;j {long count=0;
scanf("%ld %ld %ld %ld",&n,&m,&a,&d);
for(i=n;i<=m;i++)
if(i%a!=0&&i%(a+d)!=0&&i%(a+2*d)!=0&&i%(a+3*d)!=0&&i%(a+4*d)!=0)
count++;
printf("%ld\n",count);}
return 0;
}

this is second one
http://www.spoj.pl/problems/AMR11G/

include

int main()
{int t,i,n,count;
char a[50];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;iscanf("%c",&a[i]);

for(i=0;iif(a[i]=='D')
{count=0; break;}

if(count==0)
printf("You shall not pass!\n");
else
printf("Possible\n");}
return 0;
}

also please tell the diff. b/w problems solved(my are 11) and solutions accepted(mine are 45).
and thanks for your time

For EASYMATH try running the input:
1
1 2000000000 1 2

That was my point. You need to find a much more efficient solution. Your solution is what is called a "brute force" solution. They are very useful for testing purposes, but not viable solutions.

An accepted submission is when you submit code to a problem and the judge returns Accepted. Problems solves is the number of unique problems for which you have received an Accepted result.

so acc to you what should i do in both above problems so i dont get TLE.
these constitute basics of many questions and if i dont get these right i wont be able to solve any ques. on spoj.

For AMR11G, you're not taking input correctly. Read the sample inpu and problem statement.

For EASYMATH, you need to analyze the posible inputs and recognize a pattern. This is a true "problem solving" problem. The code is really inconsequential once you understand the solution on paper.

17 days later

I am getting WA.Can anyone help me.

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long LL;
LL i,j,k,t,n,m,a,d,s,z,p[4],h,MAX=4294967296LL;
LL gcd(LL a,LL b){ if(b==0) return a; return gcd(b,a%b);}
LL lcm(LL a,LL b){ return (a/gcd(a,b))*b;} 
int main()
{  
   for(scanf("%lld",&t);t--;printf("%lld\n",m-n-s))
   {  
      scanf("%lld %lld %lld %lld",&n,&m,&a,&d);
      s=0;n--;
      for(i=1;i<32;i++)
      {   
          j=0;
          if(i & 16)
          p[j++]=a+4*d;
          if(i & 8)
          p[j++]=a+3*d;
          if(i & 4)
          p[j++]=a+2*d;
          if(i & 2)
          p[j++]=a+1*d;
          if(i & 1)
          p[j++]=a;
          if(j==1)
          {       
              s+=(m/p[0]-n/p[0]);
          }
          else
          {       z=lcm(p[0],p[1]);
                  if(z<=MAX)
                  {
                       int ch=0;
                       for(k=2;k<j;k++)
                       { 
                           z=lcm(z,p[k]);
                           if(z>MAX)
                           {ch=1;break;}
                       }    
                       if(ch==0)
                       {
                           if(j&1) s+=(m/z-n/z);
                           else    s-=(m/z-n/z);
                       }
                  }               
          }
       }
   }
   return 0;
}
3 months later

Suggested Topics

Topic Category Replies Views Activity
Off-topic 1 104 Apr 9

Want to read more? Browse other topics in Off-topic or view latest topics.