does tle means that my code is correct?
but take more time than specified?
created
last reply
- 14
replies
- 912
views
- 3
users
- 1
like
- 2
links
does tle means that my code is correct?
but take more time than specified?
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.
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/
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;
}
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.
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;
}
Topic | Category | Replies | Views | Activity |
---|---|---|---|---|
Hosting a competition on SPOJ | Off-topic | 1 | 104 | Apr 9 |