Submission #172840

# Submission time Handle Problem Language Result Execution time Memory
172840 2020-01-02T16:39:15 Z LinusTorvaldsFan Money (IZhO17_money) C++14
0 / 100
2 ms 376 KB
#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
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -