[USACO16OPEN]262144 P 题解
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int f[59][262145];
int main()
{
int n,x,ans=0;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
f[x][i]=i+1;
}
for(int i=2;i<=58;i++)
for(int j=1;j<=n;j++)
{
if(!f[i][j])
f[i][j]=f[i-1][f[i-1][j]];
if(f[i][j])
ans=i;
}
cout<<ans;
}