# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
386264 | 2021-04-06T08:44:43 Z | patrikpavic2 | Money (IZhO17_money) | C++17 | 326 ms | 17132 KB |
#include <cstdio> #include <cstring> #include <vector> #include <set> #include <algorithm> #define X first #define Y second #define PB push_back using namespace std; const int N = 1e6 + 500; int A[N], n, prv[N], nxt[N], sol; int cnt[N]; void remove(int x){ prv[nxt[x]] = prv[x]; nxt[prv[x]] = nxt[x]; } int main(){ scanf("%d", &n); for(int i = 0;i < n;i++){ scanf("%d", A + i); cnt[A[i]]++; } for(int i = 1;i < N;i++){ prv[i] = i - 1; nxt[i - 1] = i; } for(int i = n - 1;i >= 0;i--){ cnt[A[i]]--; while(i > 0 && A[i - 1] == A[i]){ i--; cnt[A[i]]--; } int cur = prv[A[i]]; while(!cnt[cur] && cur > 0) { remove(cur); cur = prv[cur]; } if(i > 0 && A[i - 1] == cur){ i--; cnt[A[i]]--; } cur = A[i]; while(!cnt[cur] && cur > 0) { remove(cur); cur = prv[cur]; } while(i > 0 && A[i - 1] == cur){ i--; cnt[A[i]]--; while(!cnt[cur] && cur > 0) { remove(cur); cur = prv[cur]; } } sol++; } printf("%d\n", sol); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8172 KB | Output is correct |
2 | Correct | 6 ms | 8172 KB | Output is correct |
3 | Correct | 6 ms | 8172 KB | Output is correct |
4 | Correct | 6 ms | 8172 KB | Output is correct |
5 | Correct | 6 ms | 8172 KB | Output is correct |
6 | Correct | 6 ms | 8172 KB | Output is correct |
7 | Correct | 10 ms | 8172 KB | Output is correct |
8 | Correct | 12 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 10 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 10 ms | 8172 KB | Output is correct |
13 | Correct | 11 ms | 8172 KB | Output is correct |
14 | Correct | 10 ms | 8172 KB | Output is correct |
15 | Correct | 14 ms | 8172 KB | Output is correct |
16 | Correct | 11 ms | 8172 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8172 KB | Output is correct |
2 | Correct | 6 ms | 8172 KB | Output is correct |
3 | Correct | 6 ms | 8172 KB | Output is correct |
4 | Correct | 6 ms | 8172 KB | Output is correct |
5 | Correct | 6 ms | 8172 KB | Output is correct |
6 | Correct | 6 ms | 8172 KB | Output is correct |
7 | Correct | 10 ms | 8172 KB | Output is correct |
8 | Correct | 12 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 10 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 10 ms | 8172 KB | Output is correct |
13 | Correct | 11 ms | 8172 KB | Output is correct |
14 | Correct | 10 ms | 8172 KB | Output is correct |
15 | Correct | 14 ms | 8172 KB | Output is correct |
16 | Correct | 11 ms | 8172 KB | Output is correct |
17 | Correct | 12 ms | 8172 KB | Output is correct |
18 | Correct | 11 ms | 8172 KB | Output is correct |
19 | Correct | 11 ms | 8172 KB | Output is correct |
20 | Correct | 12 ms | 8172 KB | Output is correct |
21 | Correct | 10 ms | 8172 KB | Output is correct |
22 | Correct | 12 ms | 8300 KB | Output is correct |
23 | Correct | 11 ms | 8172 KB | Output is correct |
24 | Correct | 10 ms | 8172 KB | Output is correct |
25 | Correct | 11 ms | 8172 KB | Output is correct |
26 | Correct | 12 ms | 8172 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8172 KB | Output is correct |
2 | Correct | 6 ms | 8172 KB | Output is correct |
3 | Correct | 6 ms | 8172 KB | Output is correct |
4 | Correct | 6 ms | 8172 KB | Output is correct |
5 | Correct | 6 ms | 8172 KB | Output is correct |
6 | Correct | 6 ms | 8172 KB | Output is correct |
7 | Correct | 10 ms | 8172 KB | Output is correct |
8 | Correct | 12 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 10 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 10 ms | 8172 KB | Output is correct |
13 | Correct | 11 ms | 8172 KB | Output is correct |
14 | Correct | 10 ms | 8172 KB | Output is correct |
15 | Correct | 14 ms | 8172 KB | Output is correct |
16 | Correct | 11 ms | 8172 KB | Output is correct |
17 | Correct | 12 ms | 8172 KB | Output is correct |
18 | Correct | 11 ms | 8172 KB | Output is correct |
19 | Correct | 11 ms | 8172 KB | Output is correct |
20 | Correct | 12 ms | 8172 KB | Output is correct |
21 | Correct | 10 ms | 8172 KB | Output is correct |
22 | Correct | 12 ms | 8300 KB | Output is correct |
23 | Correct | 11 ms | 8172 KB | Output is correct |
24 | Correct | 10 ms | 8172 KB | Output is correct |
25 | Correct | 11 ms | 8172 KB | Output is correct |
26 | Correct | 12 ms | 8172 KB | Output is correct |
27 | Correct | 6 ms | 8172 KB | Output is correct |
28 | Correct | 6 ms | 8172 KB | Output is correct |
29 | Correct | 6 ms | 8172 KB | Output is correct |
30 | Correct | 6 ms | 8172 KB | Output is correct |
31 | Correct | 6 ms | 8192 KB | Output is correct |
32 | Correct | 12 ms | 8172 KB | Output is correct |
33 | Correct | 10 ms | 8172 KB | Output is correct |
34 | Correct | 12 ms | 8172 KB | Output is correct |
35 | Correct | 9 ms | 8172 KB | Output is correct |
36 | Correct | 11 ms | 8172 KB | Output is correct |
37 | Correct | 14 ms | 8684 KB | Output is correct |
38 | Correct | 13 ms | 8684 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 8172 KB | Output is correct |
2 | Correct | 6 ms | 8172 KB | Output is correct |
3 | Correct | 6 ms | 8172 KB | Output is correct |
4 | Correct | 6 ms | 8172 KB | Output is correct |
5 | Correct | 6 ms | 8172 KB | Output is correct |
6 | Correct | 6 ms | 8172 KB | Output is correct |
7 | Correct | 10 ms | 8172 KB | Output is correct |
8 | Correct | 12 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 10 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 10 ms | 8172 KB | Output is correct |
13 | Correct | 11 ms | 8172 KB | Output is correct |
14 | Correct | 10 ms | 8172 KB | Output is correct |
15 | Correct | 14 ms | 8172 KB | Output is correct |
16 | Correct | 11 ms | 8172 KB | Output is correct |
17 | Correct | 12 ms | 8172 KB | Output is correct |
18 | Correct | 11 ms | 8172 KB | Output is correct |
19 | Correct | 11 ms | 8172 KB | Output is correct |
20 | Correct | 12 ms | 8172 KB | Output is correct |
21 | Correct | 10 ms | 8172 KB | Output is correct |
22 | Correct | 12 ms | 8300 KB | Output is correct |
23 | Correct | 11 ms | 8172 KB | Output is correct |
24 | Correct | 10 ms | 8172 KB | Output is correct |
25 | Correct | 11 ms | 8172 KB | Output is correct |
26 | Correct | 12 ms | 8172 KB | Output is correct |
27 | Correct | 6 ms | 8172 KB | Output is correct |
28 | Correct | 6 ms | 8172 KB | Output is correct |
29 | Correct | 6 ms | 8172 KB | Output is correct |
30 | Correct | 6 ms | 8172 KB | Output is correct |
31 | Correct | 6 ms | 8192 KB | Output is correct |
32 | Correct | 12 ms | 8172 KB | Output is correct |
33 | Correct | 10 ms | 8172 KB | Output is correct |
34 | Correct | 12 ms | 8172 KB | Output is correct |
35 | Correct | 9 ms | 8172 KB | Output is correct |
36 | Correct | 11 ms | 8172 KB | Output is correct |
37 | Correct | 14 ms | 8684 KB | Output is correct |
38 | Correct | 13 ms | 8684 KB | Output is correct |
39 | Correct | 77 ms | 10104 KB | Output is correct |
40 | Correct | 113 ms | 11260 KB | Output is correct |
41 | Correct | 63 ms | 9728 KB | Output is correct |
42 | Correct | 57 ms | 9708 KB | Output is correct |
43 | Correct | 43 ms | 9196 KB | Output is correct |
44 | Correct | 145 ms | 12268 KB | Output is correct |
45 | Correct | 143 ms | 12096 KB | Output is correct |
46 | Correct | 147 ms | 12140 KB | Output is correct |
47 | Correct | 140 ms | 12012 KB | Output is correct |
48 | Correct | 146 ms | 12100 KB | Output is correct |
49 | Correct | 232 ms | 16016 KB | Output is correct |
50 | Correct | 225 ms | 16928 KB | Output is correct |
51 | Correct | 253 ms | 17004 KB | Output is correct |
52 | Correct | 224 ms | 16876 KB | Output is correct |
53 | Correct | 232 ms | 17004 KB | Output is correct |
54 | Correct | 281 ms | 17132 KB | Output is correct |
55 | Correct | 274 ms | 17004 KB | Output is correct |
56 | Correct | 278 ms | 17004 KB | Output is correct |
57 | Correct | 269 ms | 16876 KB | Output is correct |
58 | Correct | 326 ms | 16860 KB | Output is correct |
59 | Correct | 264 ms | 16876 KB | Output is correct |
60 | Correct | 268 ms | 16876 KB | Output is correct |
61 | Correct | 281 ms | 16932 KB | Output is correct |
62 | Correct | 274 ms | 16876 KB | Output is correct |