|
|
back to boardif u wanna AC, u must know the value of LCM (by GCD is easy) and Search cycles.:) Re: if u wanna AC, u must know the value of LCM (by GCD is easy) and Search cycles.:) Posted by Hany 1 Sep 2003 16:37 explain it by code i got time limit exceeded, my code is :::: #include<stdio.h> #include<iostream.h> main() { int n; cin>>n; int *arr=new int[n]; int *result=new int[n];
for(int i=0;i<n;i++) cin>>arr[i];
int max=1,temp; bool x=true; while(1) { temp=0; for(int i=0;i<n;i++) { temp=i; for(int j=0;j<max;j++) { result[i]=arr[temp]; temp=result[i]-1; } if(result[i]!=i+1) { x=false; break; } } if(x==false) { x=true; max++; continue; } cout<<max<<endl; break; } } |
|
|