|
|
back to boardCould somebody tell me what's wrong with my solution ?. Posted by jh 17 Mar 2003 02:21 #include <iostream.h> #include <stdlib.h> #define MAX 130001 long t[MAX],s[MAX]; long n,i,tmp,j,tgcd; long gcd(long a, long b){ long tmp; while (b>0){ tmp = a%b; a=b; b=tmp; } return a; } int main(){ cin >> n; for (i=0;i<MAX;++i) s[i]=0; for (i=1; i<=n;++i){ cin >>tmp; s[tmp]=i; } j=0; for (i=1;i<MAX; ++i) if (s[i]) t[++j]=s[i]; tgcd = t[1]-1; for (j=2;j<=n;++j){ if (t[j]>j) tgcd=gcd(tgcd,t[j]-j); if (t[j]<j) tgcd = gcd(tgcd,j-t[j]);
} tgcd = (tgcd) ? tgcd-1 : 0; cout << tgcd<<endl; return 0; } Re: Could somebody tell me what's wrong with my solution ?. Posted by rafal 17 Mar 2003 06:02 > #define MAX 130001 > (...) > long t[MAX],s[MAX]; > (...) 2*4*130001 bytes = 1040008 bytes > 1015 kilobytes the limit is 1000K Re: Could somebody tell me what's wrong with my solution ?. Posted by jh 18 Mar 2003 00:05 > > #define MAX 130001 > > (...) > > long t[MAX],s[MAX]; > > (...) > 2*4*130001 bytes = 1040008 bytes > 1015 kilobytes > > the limit is 1000K It can be easy fixed, but i still got WA, anyway what's the answer for 4 1 2 3 4 3 or 0 or something else ? |
|
|