# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
386262 | 2021-04-06T08:42:52 Z | patrikpavic2 | Money (IZhO17_money) | C++17 | 1500 ms | 10092 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 = A[i] - 1; 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 | 14 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 12 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 13 ms | 8172 KB | Output is correct |
13 | Correct | 15 ms | 8172 KB | Output is correct |
14 | Correct | 13 ms | 8172 KB | Output is correct |
15 | Correct | 12 ms | 8172 KB | Output is correct |
16 | Correct | 13 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 | 14 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 12 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 13 ms | 8172 KB | Output is correct |
13 | Correct | 15 ms | 8172 KB | Output is correct |
14 | Correct | 13 ms | 8172 KB | Output is correct |
15 | Correct | 12 ms | 8172 KB | Output is correct |
16 | Correct | 13 ms | 8172 KB | Output is correct |
17 | Correct | 19 ms | 8172 KB | Output is correct |
18 | Correct | 15 ms | 8172 KB | Output is correct |
19 | Correct | 13 ms | 8172 KB | Output is correct |
20 | Correct | 18 ms | 8172 KB | Output is correct |
21 | Correct | 15 ms | 8172 KB | Output is correct |
22 | Correct | 24 ms | 8172 KB | Output is correct |
23 | Correct | 13 ms | 8172 KB | Output is correct |
24 | Correct | 23 ms | 8172 KB | Output is correct |
25 | Correct | 12 ms | 8320 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 | 14 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 12 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 13 ms | 8172 KB | Output is correct |
13 | Correct | 15 ms | 8172 KB | Output is correct |
14 | Correct | 13 ms | 8172 KB | Output is correct |
15 | Correct | 12 ms | 8172 KB | Output is correct |
16 | Correct | 13 ms | 8172 KB | Output is correct |
17 | Correct | 19 ms | 8172 KB | Output is correct |
18 | Correct | 15 ms | 8172 KB | Output is correct |
19 | Correct | 13 ms | 8172 KB | Output is correct |
20 | Correct | 18 ms | 8172 KB | Output is correct |
21 | Correct | 15 ms | 8172 KB | Output is correct |
22 | Correct | 24 ms | 8172 KB | Output is correct |
23 | Correct | 13 ms | 8172 KB | Output is correct |
24 | Correct | 23 ms | 8172 KB | Output is correct |
25 | Correct | 12 ms | 8320 KB | Output is correct |
26 | Correct | 12 ms | 8172 KB | Output is correct |
27 | Correct | 6 ms | 8172 KB | Output is correct |
28 | Correct | 5 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 | 184 ms | 8300 KB | Output is correct |
33 | Correct | 181 ms | 8220 KB | Output is correct |
34 | Correct | 178 ms | 8172 KB | Output is correct |
35 | Correct | 55 ms | 8172 KB | Output is correct |
36 | Correct | 215 ms | 8172 KB | Output is correct |
37 | Correct | 16 ms | 8684 KB | Output is correct |
38 | Correct | 15 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 | 14 ms | 8172 KB | Output is correct |
9 | Correct | 10 ms | 8172 KB | Output is correct |
10 | Correct | 12 ms | 8172 KB | Output is correct |
11 | Correct | 11 ms | 8172 KB | Output is correct |
12 | Correct | 13 ms | 8172 KB | Output is correct |
13 | Correct | 15 ms | 8172 KB | Output is correct |
14 | Correct | 13 ms | 8172 KB | Output is correct |
15 | Correct | 12 ms | 8172 KB | Output is correct |
16 | Correct | 13 ms | 8172 KB | Output is correct |
17 | Correct | 19 ms | 8172 KB | Output is correct |
18 | Correct | 15 ms | 8172 KB | Output is correct |
19 | Correct | 13 ms | 8172 KB | Output is correct |
20 | Correct | 18 ms | 8172 KB | Output is correct |
21 | Correct | 15 ms | 8172 KB | Output is correct |
22 | Correct | 24 ms | 8172 KB | Output is correct |
23 | Correct | 13 ms | 8172 KB | Output is correct |
24 | Correct | 23 ms | 8172 KB | Output is correct |
25 | Correct | 12 ms | 8320 KB | Output is correct |
26 | Correct | 12 ms | 8172 KB | Output is correct |
27 | Correct | 6 ms | 8172 KB | Output is correct |
28 | Correct | 5 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 | 184 ms | 8300 KB | Output is correct |
33 | Correct | 181 ms | 8220 KB | Output is correct |
34 | Correct | 178 ms | 8172 KB | Output is correct |
35 | Correct | 55 ms | 8172 KB | Output is correct |
36 | Correct | 215 ms | 8172 KB | Output is correct |
37 | Correct | 16 ms | 8684 KB | Output is correct |
38 | Correct | 15 ms | 8684 KB | Output is correct |
39 | Execution timed out | 1589 ms | 10092 KB | Time limit exceeded |
40 | Halted | 0 ms | 0 KB | - |