# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
36244 | 2017-12-06T13:53:26 Z | touristk2000 | Money (IZhO17_money) | C++14 | 556 ms | 17648 KB |
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)1e6 + 1; int main(){ int n; scanf("%d", &n); vector<int> a(n); vector<int> cnt(MAXN); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); cnt[a[i]]++; } vector<int> pr(MAXN + 1), nxt(MAXN + 1, MAXN); { int lst = 0; for (int i = 1; i <= MAXN; ++i) { pr[i] = lst; if (cnt[i]) nxt[lst] = i, lst = i; } } int ans = 0; for (int i = n - 1; i >= 0;) { ++ans; int j = i; while (i > 0) { int p = pr[a[i]]; if (a[i - 1] == a[i]) { if (cnt[a[i]] == 1) { int l = pr[a[i]]; int r = nxt[a[i]]; pr[r] = l; nxt[l] = r; } --cnt[a[i]]; --i; } else { if (p == a[i - 1] && (cnt[a[i]] == 1 || a[j] == a[i])) { if (cnt[a[i]] == 1) { int l = pr[a[i]]; int r = nxt[a[i]]; pr[r] = l; nxt[l] = r; } --cnt[a[i]]; --i; } else { break; } } } if (cnt[a[i]] == 1) { int l = pr[a[i]]; int r = nxt[a[i]]; pr[r] = l; nxt[l] = r; } --cnt[a[i]]; --i; } printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 13740 KB | Output is correct |
2 | Correct | 3 ms | 13740 KB | Output is correct |
3 | Correct | 3 ms | 13740 KB | Output is correct |
4 | Correct | 3 ms | 13740 KB | Output is correct |
5 | Correct | 0 ms | 13740 KB | Output is correct |
6 | Correct | 3 ms | 13740 KB | Output is correct |
7 | Correct | 3 ms | 13740 KB | Output is correct |
8 | Correct | 0 ms | 13740 KB | Output is correct |
9 | Correct | 6 ms | 13740 KB | Output is correct |
10 | Correct | 6 ms | 13740 KB | Output is correct |
11 | Correct | 0 ms | 13740 KB | Output is correct |
12 | Correct | 6 ms | 13740 KB | Output is correct |
13 | Correct | 3 ms | 13740 KB | Output is correct |
14 | Correct | 3 ms | 13740 KB | Output is correct |
15 | Correct | 0 ms | 13740 KB | Output is correct |
16 | Correct | 3 ms | 13740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 13740 KB | Output is correct |
2 | Correct | 3 ms | 13740 KB | Output is correct |
3 | Correct | 3 ms | 13740 KB | Output is correct |
4 | Correct | 3 ms | 13740 KB | Output is correct |
5 | Correct | 0 ms | 13740 KB | Output is correct |
6 | Correct | 3 ms | 13740 KB | Output is correct |
7 | Correct | 3 ms | 13740 KB | Output is correct |
8 | Correct | 0 ms | 13740 KB | Output is correct |
9 | Correct | 6 ms | 13740 KB | Output is correct |
10 | Correct | 6 ms | 13740 KB | Output is correct |
11 | Correct | 0 ms | 13740 KB | Output is correct |
12 | Correct | 6 ms | 13740 KB | Output is correct |
13 | Correct | 3 ms | 13740 KB | Output is correct |
14 | Correct | 3 ms | 13740 KB | Output is correct |
15 | Correct | 0 ms | 13740 KB | Output is correct |
16 | Correct | 3 ms | 13740 KB | Output is correct |
17 | Correct | 13 ms | 13740 KB | Output is correct |
18 | Correct | 6 ms | 13740 KB | Output is correct |
19 | Correct | 6 ms | 13740 KB | Output is correct |
20 | Correct | 0 ms | 13740 KB | Output is correct |
21 | Correct | 3 ms | 13740 KB | Output is correct |
22 | Correct | 3 ms | 13740 KB | Output is correct |
23 | Correct | 3 ms | 13740 KB | Output is correct |
24 | Correct | 3 ms | 13740 KB | Output is correct |
25 | Correct | 3 ms | 13740 KB | Output is correct |
26 | Correct | 0 ms | 13740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 13740 KB | Output is correct |
2 | Correct | 3 ms | 13740 KB | Output is correct |
3 | Correct | 3 ms | 13740 KB | Output is correct |
4 | Correct | 3 ms | 13740 KB | Output is correct |
5 | Correct | 0 ms | 13740 KB | Output is correct |
6 | Correct | 3 ms | 13740 KB | Output is correct |
7 | Correct | 3 ms | 13740 KB | Output is correct |
8 | Correct | 0 ms | 13740 KB | Output is correct |
9 | Correct | 6 ms | 13740 KB | Output is correct |
10 | Correct | 6 ms | 13740 KB | Output is correct |
11 | Correct | 0 ms | 13740 KB | Output is correct |
12 | Correct | 6 ms | 13740 KB | Output is correct |
13 | Correct | 3 ms | 13740 KB | Output is correct |
14 | Correct | 3 ms | 13740 KB | Output is correct |
15 | Correct | 0 ms | 13740 KB | Output is correct |
16 | Correct | 3 ms | 13740 KB | Output is correct |
17 | Correct | 13 ms | 13740 KB | Output is correct |
18 | Correct | 6 ms | 13740 KB | Output is correct |
19 | Correct | 6 ms | 13740 KB | Output is correct |
20 | Correct | 0 ms | 13740 KB | Output is correct |
21 | Correct | 3 ms | 13740 KB | Output is correct |
22 | Correct | 3 ms | 13740 KB | Output is correct |
23 | Correct | 3 ms | 13740 KB | Output is correct |
24 | Correct | 3 ms | 13740 KB | Output is correct |
25 | Correct | 3 ms | 13740 KB | Output is correct |
26 | Correct | 0 ms | 13740 KB | Output is correct |
27 | Correct | 3 ms | 13740 KB | Output is correct |
28 | Correct | 6 ms | 13740 KB | Output is correct |
29 | Correct | 6 ms | 13740 KB | Output is correct |
30 | Correct | 0 ms | 13740 KB | Output is correct |
31 | Correct | 9 ms | 13740 KB | Output is correct |
32 | Correct | 3 ms | 13740 KB | Output is correct |
33 | Correct | 6 ms | 13740 KB | Output is correct |
34 | Correct | 3 ms | 13740 KB | Output is correct |
35 | Correct | 0 ms | 13740 KB | Output is correct |
36 | Correct | 0 ms | 13740 KB | Output is correct |
37 | Correct | 3 ms | 13740 KB | Output is correct |
38 | Correct | 3 ms | 13740 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 13740 KB | Output is correct |
2 | Correct | 3 ms | 13740 KB | Output is correct |
3 | Correct | 3 ms | 13740 KB | Output is correct |
4 | Correct | 3 ms | 13740 KB | Output is correct |
5 | Correct | 0 ms | 13740 KB | Output is correct |
6 | Correct | 3 ms | 13740 KB | Output is correct |
7 | Correct | 3 ms | 13740 KB | Output is correct |
8 | Correct | 0 ms | 13740 KB | Output is correct |
9 | Correct | 6 ms | 13740 KB | Output is correct |
10 | Correct | 6 ms | 13740 KB | Output is correct |
11 | Correct | 0 ms | 13740 KB | Output is correct |
12 | Correct | 6 ms | 13740 KB | Output is correct |
13 | Correct | 3 ms | 13740 KB | Output is correct |
14 | Correct | 3 ms | 13740 KB | Output is correct |
15 | Correct | 0 ms | 13740 KB | Output is correct |
16 | Correct | 3 ms | 13740 KB | Output is correct |
17 | Correct | 13 ms | 13740 KB | Output is correct |
18 | Correct | 6 ms | 13740 KB | Output is correct |
19 | Correct | 6 ms | 13740 KB | Output is correct |
20 | Correct | 0 ms | 13740 KB | Output is correct |
21 | Correct | 3 ms | 13740 KB | Output is correct |
22 | Correct | 3 ms | 13740 KB | Output is correct |
23 | Correct | 3 ms | 13740 KB | Output is correct |
24 | Correct | 3 ms | 13740 KB | Output is correct |
25 | Correct | 3 ms | 13740 KB | Output is correct |
26 | Correct | 0 ms | 13740 KB | Output is correct |
27 | Correct | 3 ms | 13740 KB | Output is correct |
28 | Correct | 6 ms | 13740 KB | Output is correct |
29 | Correct | 6 ms | 13740 KB | Output is correct |
30 | Correct | 0 ms | 13740 KB | Output is correct |
31 | Correct | 9 ms | 13740 KB | Output is correct |
32 | Correct | 3 ms | 13740 KB | Output is correct |
33 | Correct | 6 ms | 13740 KB | Output is correct |
34 | Correct | 3 ms | 13740 KB | Output is correct |
35 | Correct | 0 ms | 13740 KB | Output is correct |
36 | Correct | 0 ms | 13740 KB | Output is correct |
37 | Correct | 3 ms | 13740 KB | Output is correct |
38 | Correct | 3 ms | 13740 KB | Output is correct |
39 | Correct | 76 ms | 15620 KB | Output is correct |
40 | Correct | 143 ms | 16824 KB | Output is correct |
41 | Correct | 96 ms | 15260 KB | Output is correct |
42 | Correct | 63 ms | 15084 KB | Output is correct |
43 | Correct | 49 ms | 14688 KB | Output is correct |
44 | Correct | 189 ms | 17648 KB | Output is correct |
45 | Correct | 186 ms | 17648 KB | Output is correct |
46 | Correct | 156 ms | 17648 KB | Output is correct |
47 | Correct | 169 ms | 17648 KB | Output is correct |
48 | Correct | 236 ms | 17648 KB | Output is correct |
49 | Correct | 326 ms | 17648 KB | Output is correct |
50 | Correct | 299 ms | 17648 KB | Output is correct |
51 | Correct | 366 ms | 17648 KB | Output is correct |
52 | Correct | 413 ms | 17648 KB | Output is correct |
53 | Correct | 349 ms | 17648 KB | Output is correct |
54 | Correct | 366 ms | 17648 KB | Output is correct |
55 | Correct | 466 ms | 17648 KB | Output is correct |
56 | Correct | 449 ms | 17648 KB | Output is correct |
57 | Correct | 496 ms | 17648 KB | Output is correct |
58 | Correct | 456 ms | 17648 KB | Output is correct |
59 | Correct | 459 ms | 17648 KB | Output is correct |
60 | Correct | 536 ms | 17648 KB | Output is correct |
61 | Correct | 556 ms | 17648 KB | Output is correct |
62 | Correct | 529 ms | 17648 KB | Output is correct |