Submission #44693

# Submission time Handle Problem Language Result Execution time Memory
44693 2018-04-04T20:30:34 Z heon Baloni (COCI15_baloni) C++14
100 / 100
1952 ms 94976 KB
#include<bits/stdc++.h>

using namespace std;

const int maxn = 1 << 20;

int n;
set <int> st[maxn];
int x[maxn];

auto nadi(int id, int height){
	auto it = st[height].lower_bound(id);
	if(it == st[height].end()) return -1;
	return *it;
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x[i];
		st[x[i]].insert(i);
	}
	int sol = 0;
	for(int i = 0; i < n; i++){
		if(!st[x[i]].count(i)) continue;
		sol++;
		int pos = i;
		while(pos >= 0){
			st[x[pos]].erase(pos);
			pos = nadi(pos,x[pos]-1);
		}
	}
	cout << sol;
}
# Verdict Execution time Memory Grader output
1 Correct 40 ms 49656 KB Output is correct
2 Correct 40 ms 49860 KB Output is correct
3 Correct 42 ms 49948 KB Output is correct
4 Correct 43 ms 49948 KB Output is correct
5 Correct 1780 ms 90020 KB Output is correct
6 Correct 1952 ms 94976 KB Output is correct
7 Correct 1524 ms 94976 KB Output is correct
8 Correct 1538 ms 94976 KB Output is correct
9 Correct 1730 ms 94976 KB Output is correct
10 Correct 1725 ms 94976 KB Output is correct