Submission #172840

#TimeUsernameProblemLanguageResultExecution timeMemory
172840LinusTorvaldsFanMoney (IZhO17_money)C++14
0 / 100
2 ms376 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...