|
|
back to boardwhy time limit exited ? #include<iostream> using namespace std; int main(void) { int ary1[1000],ary2[1000],n=5,input,result=1,m=0; cin>>n; if(n<1&&n>1000) exit(0); for(int i=0;i<n;i++) { cin>>input; ary2[i]=ary1[i]=input; } for(int x=0;x<n;x++) { if(ary1[x]!=(x+1)) break; else m++; } if(m==n) { cout<<result; exit(0); } else m=0; while(1) { for(int j=0;j<n;j++) { ary2[j]=ary1[ary2[j]-1];
} result++; for(int k=0;k<n;k++) { if(ary2[k]!=(k+1)) break; else m++; } if(m==n) { cout<<result; exit(0); } else m=0; } return 0; } |
|
|