This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
vector<int>a(n);
for(int i=0;i<n;i++)cin>>a[i];
vector<int>nei(n+1);
vector<bool>al(n,true);
for(int i=0;i<n;i++){
nei[i+1]=i+2;
}
int ans=0;
while(true) {
bool br=true;
int ind=-1;
int am=0;
for(int i=0;i<n;i++){
if(!al[i])continue;
br=false;
int j=i+1;
int cur=1;
while(j<n&&a[j]==nei[a[j-1]]){
j++;
cur++;
}
if(cur>am){
am=cur;
ind=i;
}
}
if(br)break;
ans++;
for(int i=ind;i<ind+am;i++){
al[i]=false;
}
nei[a[ind]-1]=a[ind]+am;
}
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |