|
|
back to boardWhich algorithms you use ? I got "Time Limit Exceeded" ... see my code (in C) #include<stdio.h> int p[1000],tmp[1000]; int n; int go(int t,int i){ int j,v;
v=p[i]; for(j=1;j<t;j++) v=p[v-1]; return v; } int checkout(int t){ int i;
for(i=0;i<n;i++){ tmp[i]=go(t,i); if(tmp[i] != i+1) return checkout(t+1); } return t; } int main(){ int i; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&p[i]); printf("%d\n",checkout(1)); return 0; } |
|
|