Submission #442129

# Submission time Handle Problem Language Result Execution time Memory
442129 2021-07-07T07:47:43 Z Nima_Naderi Money (IZhO17_money) C++14
45 / 100
1500 ms 59104 KB
//In the name of GOD
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;

typedef int ll;
const ll MXN = 1e6 + 10;
ll n, ans;
ll A[MXN], cnt[MXN], blk[MXN];
set<ll> st;
bool next(ll x, ll y){
	auto itr = st.find(x);
	if(itr == st.end()) return 0;
	itr ++;
	if(itr == st.end() || *itr != y) return 0;
	return 1;
}
void relax(ll x, ll t){
	cnt[x] -= t; assert(cnt[x] >= 0);
	if(!cnt[x]){
		auto itr = st.find(x);
		st.erase(itr);
	}
}
void solve(ll m){
	if(!m) return;
	ll pnt = m - 1, last = A[m], t = 1;
	while(pnt >= 1){
		if(A[pnt] == last){
			t ++; pnt --;
			continue;
		}
		if(!next(A[pnt], last)){
			break;
		}
		if(last == A[m]){
			relax(last, t);
			t = 1, last = A[pnt];
			pnt --;
			continue;
		}
		if(t != cnt[last]) break;
		relax(last, t);
		t = 1, last = A[pnt];
		pnt --;
	}
	relax(last, t);
	ans ++, solve(pnt);
}
int main(){
	ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i ++) cin >> A[i], cnt[A[i]] ++, st.insert(A[i]);
	for(int i = 1; i <= n; i ++) blk[i] = (A[i] != A[i - 1] ? 0 : blk[i - 1]) + 1;
	solve(n);
	cout << ans << '\n';
	return 0;
}
//! N.N
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 1 ms 844 KB Output is correct
38 Correct 1 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 0 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 0 ms 332 KB Output is correct
37 Correct 1 ms 844 KB Output is correct
38 Correct 1 ms 844 KB Output is correct
39 Correct 70 ms 4004 KB Output is correct
40 Correct 127 ms 6556 KB Output is correct
41 Correct 56 ms 3348 KB Output is correct
42 Correct 55 ms 3040 KB Output is correct
43 Correct 40 ms 2160 KB Output is correct
44 Correct 150 ms 8108 KB Output is correct
45 Correct 155 ms 8188 KB Output is correct
46 Correct 156 ms 8156 KB Output is correct
47 Correct 129 ms 8080 KB Output is correct
48 Correct 134 ms 8132 KB Output is correct
49 Correct 755 ms 30512 KB Output is correct
50 Correct 748 ms 30568 KB Output is correct
51 Correct 743 ms 30628 KB Output is correct
52 Correct 717 ms 30532 KB Output is correct
53 Correct 729 ms 30520 KB Output is correct
54 Correct 742 ms 30588 KB Output is correct
55 Execution timed out 1593 ms 59104 KB Time limit exceeded
56 Halted 0 ms 0 KB -