ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1024. Permutations

if u wanna AC, u must know the value of LCM (by GCD is easy) and Search cycles.:)
Posted by Coldfeel 19 Nov 2002 16:31
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;
 }
}