hi friends!!!
i am gettting tle in the problem ABCDEF.... below is my code...
what i am doing is that i am finding all possible combinations for the lhs and rhs after rewriting the equation as (a*b) +c = d*(e+f) (ignoring zero values of d, of course).. then i just sorted the two arrays storing the combinations... on comparing the the sorted arrays for equality of elements, i increment the counter... but m getting tle ... m puzzled...
seems sorting is a bit inefficient. it will be good if sm1 looks into this plz...
include
include
using namespace std;
int comp(const void *p1,const void *p2)
{
return ((int *)p1)-((int *)p2);
}
int main()
{
int a[105],s1[1000000],s2[1000000],s3[1000000];
int i,j,k,n,c1=0,c2=0;
long long sum=0;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
{ s1[c1]=(a[i]*a[j])+a[k];
s3[c1++]=a[i]+a[j]+a[k];
if(a[i])
s2[c2++]=a[i]*(a[j]+a[k]);
}
qsort(s1,c1,sizeof(int),comp);
qsort(s2,c2,sizeof(int),comp);
for(i=0;i<c1;i++)
for(j=0;j<c2;j++)
{ if(s1[i]==s2[j])
sum++;
}
printf("%lld",sum);
return 0;
}
thanx in advance..!!!!