# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
128887 | 2019-07-11T10:41:00 Z | youngyojun | Rope (JOI17_rope) | C++11 | 988 ms | 115904 KB |
#include <bits/stdc++.h> #define rf(x) (x)=0;while(*p<48)p++;while(47<*p)(x)=((x)<<3)+((x)<<1)+(*p++&15); #define eb emplace_back using namespace std; typedef unsigned int ui; static unsigned char str[9900099], *p=str; const int MAXN = 1000055; ui D[MAXN][2]; bitset<MAXN> chk; vector<int> G[MAXN]; vector<ui> T[MAXN]; ui O[MAXN]; ui A[MAXN], B[MAXN]; ui N, M; int main() { fread(str, 1, 9900099, stdin); rf(N) rf(M) for(ui i = N; i; i--) { rf(A[i]) B[A[i]]++; } for(ui i = M; i; i--) T[B[i]].eb(i); for(ui i = N, c = 0; i; i--) for(ui v : T[i]) O[++c] = v; for(int i = 1; i < N; i++) if(A[i] != A[i+1]) { G[A[i]].eb(i+1); G[A[i+1]].eb(-i); } for(ui i = 1; i <= M; i++) { int ret = 0, dg = 0; for(int v : G[i]) { D[A[v < 0 ? -v : v]][(0 < v ? v-1 : -v)&1]++; chk[A[v < 0 ? -v : v]] = true; dg++; } for(ui oi = 1, c; oi <= M && oi <= dg+2; oi++) { c = O[oi]; if(c == i || chk[c]) continue; ret = -int(B[c]); break; } for(int v : G[i]) { int c = A[v < 0 ? -v : v], t = min(D[c][0], D[c][1]) - B[c]; if(t < ret) ret = t; } for(int v : G[i]) { D[A[v < 0 ? -v : v]][(0 < v ? v-1 : -v)&1] = 0; chk[A[v < 0 ? -v : v]] = false; } printf("%d\n", ret + N-B[i]); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47324 KB | Output is correct |
2 | Correct | 44 ms | 47396 KB | Output is correct |
3 | Correct | 44 ms | 47380 KB | Output is correct |
4 | Correct | 45 ms | 47332 KB | Output is correct |
5 | Correct | 45 ms | 47300 KB | Output is correct |
6 | Correct | 45 ms | 47312 KB | Output is correct |
7 | Correct | 44 ms | 47352 KB | Output is correct |
8 | Correct | 46 ms | 47372 KB | Output is correct |
9 | Correct | 44 ms | 47364 KB | Output is correct |
10 | Correct | 44 ms | 47296 KB | Output is correct |
11 | Correct | 45 ms | 47380 KB | Output is correct |
12 | Correct | 45 ms | 47324 KB | Output is correct |
13 | Correct | 44 ms | 47352 KB | Output is correct |
14 | Correct | 44 ms | 47324 KB | Output is correct |
15 | Correct | 44 ms | 47352 KB | Output is correct |
16 | Correct | 44 ms | 47352 KB | Output is correct |
17 | Correct | 44 ms | 47352 KB | Output is correct |
18 | Correct | 44 ms | 47324 KB | Output is correct |
19 | Correct | 44 ms | 47352 KB | Output is correct |
20 | Correct | 43 ms | 47324 KB | Output is correct |
21 | Correct | 45 ms | 47324 KB | Output is correct |
22 | Correct | 44 ms | 47368 KB | Output is correct |
23 | Correct | 45 ms | 47352 KB | Output is correct |
24 | Correct | 45 ms | 47480 KB | Output is correct |
25 | Correct | 45 ms | 47352 KB | Output is correct |
26 | Correct | 45 ms | 47316 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47324 KB | Output is correct |
2 | Correct | 44 ms | 47396 KB | Output is correct |
3 | Correct | 44 ms | 47380 KB | Output is correct |
4 | Correct | 45 ms | 47332 KB | Output is correct |
5 | Correct | 45 ms | 47300 KB | Output is correct |
6 | Correct | 45 ms | 47312 KB | Output is correct |
7 | Correct | 44 ms | 47352 KB | Output is correct |
8 | Correct | 46 ms | 47372 KB | Output is correct |
9 | Correct | 44 ms | 47364 KB | Output is correct |
10 | Correct | 44 ms | 47296 KB | Output is correct |
11 | Correct | 45 ms | 47380 KB | Output is correct |
12 | Correct | 45 ms | 47324 KB | Output is correct |
13 | Correct | 44 ms | 47352 KB | Output is correct |
14 | Correct | 44 ms | 47324 KB | Output is correct |
15 | Correct | 44 ms | 47352 KB | Output is correct |
16 | Correct | 44 ms | 47352 KB | Output is correct |
17 | Correct | 44 ms | 47352 KB | Output is correct |
18 | Correct | 44 ms | 47324 KB | Output is correct |
19 | Correct | 44 ms | 47352 KB | Output is correct |
20 | Correct | 43 ms | 47324 KB | Output is correct |
21 | Correct | 45 ms | 47324 KB | Output is correct |
22 | Correct | 44 ms | 47368 KB | Output is correct |
23 | Correct | 45 ms | 47352 KB | Output is correct |
24 | Correct | 45 ms | 47480 KB | Output is correct |
25 | Correct | 45 ms | 47352 KB | Output is correct |
26 | Correct | 45 ms | 47316 KB | Output is correct |
27 | Correct | 52 ms | 49172 KB | Output is correct |
28 | Correct | 51 ms | 48824 KB | Output is correct |
29 | Correct | 57 ms | 49144 KB | Output is correct |
30 | Correct | 53 ms | 48812 KB | Output is correct |
31 | Correct | 68 ms | 49188 KB | Output is correct |
32 | Correct | 59 ms | 48736 KB | Output is correct |
33 | Correct | 53 ms | 49016 KB | Output is correct |
34 | Correct | 52 ms | 48632 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47324 KB | Output is correct |
2 | Correct | 44 ms | 47396 KB | Output is correct |
3 | Correct | 44 ms | 47380 KB | Output is correct |
4 | Correct | 45 ms | 47332 KB | Output is correct |
5 | Correct | 45 ms | 47300 KB | Output is correct |
6 | Correct | 45 ms | 47312 KB | Output is correct |
7 | Correct | 44 ms | 47352 KB | Output is correct |
8 | Correct | 46 ms | 47372 KB | Output is correct |
9 | Correct | 44 ms | 47364 KB | Output is correct |
10 | Correct | 44 ms | 47296 KB | Output is correct |
11 | Correct | 45 ms | 47380 KB | Output is correct |
12 | Correct | 45 ms | 47324 KB | Output is correct |
13 | Correct | 44 ms | 47352 KB | Output is correct |
14 | Correct | 44 ms | 47324 KB | Output is correct |
15 | Correct | 44 ms | 47352 KB | Output is correct |
16 | Correct | 44 ms | 47352 KB | Output is correct |
17 | Correct | 44 ms | 47352 KB | Output is correct |
18 | Correct | 44 ms | 47324 KB | Output is correct |
19 | Correct | 44 ms | 47352 KB | Output is correct |
20 | Correct | 43 ms | 47324 KB | Output is correct |
21 | Correct | 45 ms | 47324 KB | Output is correct |
22 | Correct | 44 ms | 47368 KB | Output is correct |
23 | Correct | 45 ms | 47352 KB | Output is correct |
24 | Correct | 45 ms | 47480 KB | Output is correct |
25 | Correct | 45 ms | 47352 KB | Output is correct |
26 | Correct | 45 ms | 47316 KB | Output is correct |
27 | Correct | 52 ms | 49172 KB | Output is correct |
28 | Correct | 51 ms | 48824 KB | Output is correct |
29 | Correct | 57 ms | 49144 KB | Output is correct |
30 | Correct | 53 ms | 48812 KB | Output is correct |
31 | Correct | 68 ms | 49188 KB | Output is correct |
32 | Correct | 59 ms | 48736 KB | Output is correct |
33 | Correct | 53 ms | 49016 KB | Output is correct |
34 | Correct | 52 ms | 48632 KB | Output is correct |
35 | Correct | 56 ms | 49284 KB | Output is correct |
36 | Correct | 56 ms | 49144 KB | Output is correct |
37 | Correct | 55 ms | 49128 KB | Output is correct |
38 | Correct | 57 ms | 49220 KB | Output is correct |
39 | Correct | 55 ms | 49188 KB | Output is correct |
40 | Correct | 56 ms | 49400 KB | Output is correct |
41 | Correct | 55 ms | 49456 KB | Output is correct |
42 | Correct | 54 ms | 49272 KB | Output is correct |
43 | Correct | 54 ms | 49400 KB | Output is correct |
44 | Correct | 54 ms | 49388 KB | Output is correct |
45 | Correct | 55 ms | 49468 KB | Output is correct |
46 | Correct | 55 ms | 49272 KB | Output is correct |
47 | Correct | 54 ms | 49404 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47324 KB | Output is correct |
2 | Correct | 44 ms | 47396 KB | Output is correct |
3 | Correct | 44 ms | 47380 KB | Output is correct |
4 | Correct | 45 ms | 47332 KB | Output is correct |
5 | Correct | 45 ms | 47300 KB | Output is correct |
6 | Correct | 45 ms | 47312 KB | Output is correct |
7 | Correct | 44 ms | 47352 KB | Output is correct |
8 | Correct | 46 ms | 47372 KB | Output is correct |
9 | Correct | 44 ms | 47364 KB | Output is correct |
10 | Correct | 44 ms | 47296 KB | Output is correct |
11 | Correct | 45 ms | 47380 KB | Output is correct |
12 | Correct | 45 ms | 47324 KB | Output is correct |
13 | Correct | 44 ms | 47352 KB | Output is correct |
14 | Correct | 44 ms | 47324 KB | Output is correct |
15 | Correct | 44 ms | 47352 KB | Output is correct |
16 | Correct | 44 ms | 47352 KB | Output is correct |
17 | Correct | 44 ms | 47352 KB | Output is correct |
18 | Correct | 44 ms | 47324 KB | Output is correct |
19 | Correct | 44 ms | 47352 KB | Output is correct |
20 | Correct | 43 ms | 47324 KB | Output is correct |
21 | Correct | 45 ms | 47324 KB | Output is correct |
22 | Correct | 44 ms | 47368 KB | Output is correct |
23 | Correct | 45 ms | 47352 KB | Output is correct |
24 | Correct | 45 ms | 47480 KB | Output is correct |
25 | Correct | 45 ms | 47352 KB | Output is correct |
26 | Correct | 45 ms | 47316 KB | Output is correct |
27 | Correct | 52 ms | 49172 KB | Output is correct |
28 | Correct | 51 ms | 48824 KB | Output is correct |
29 | Correct | 57 ms | 49144 KB | Output is correct |
30 | Correct | 53 ms | 48812 KB | Output is correct |
31 | Correct | 68 ms | 49188 KB | Output is correct |
32 | Correct | 59 ms | 48736 KB | Output is correct |
33 | Correct | 53 ms | 49016 KB | Output is correct |
34 | Correct | 52 ms | 48632 KB | Output is correct |
35 | Correct | 56 ms | 49284 KB | Output is correct |
36 | Correct | 56 ms | 49144 KB | Output is correct |
37 | Correct | 55 ms | 49128 KB | Output is correct |
38 | Correct | 57 ms | 49220 KB | Output is correct |
39 | Correct | 55 ms | 49188 KB | Output is correct |
40 | Correct | 56 ms | 49400 KB | Output is correct |
41 | Correct | 55 ms | 49456 KB | Output is correct |
42 | Correct | 54 ms | 49272 KB | Output is correct |
43 | Correct | 54 ms | 49400 KB | Output is correct |
44 | Correct | 54 ms | 49388 KB | Output is correct |
45 | Correct | 55 ms | 49468 KB | Output is correct |
46 | Correct | 55 ms | 49272 KB | Output is correct |
47 | Correct | 54 ms | 49404 KB | Output is correct |
48 | Correct | 194 ms | 69052 KB | Output is correct |
49 | Correct | 205 ms | 69080 KB | Output is correct |
50 | Correct | 198 ms | 68956 KB | Output is correct |
51 | Correct | 202 ms | 68600 KB | Output is correct |
52 | Correct | 186 ms | 65756 KB | Output is correct |
53 | Correct | 175 ms | 67504 KB | Output is correct |
54 | Correct | 175 ms | 65532 KB | Output is correct |
55 | Correct | 163 ms | 65188 KB | Output is correct |
56 | Correct | 169 ms | 64668 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 44 ms | 47324 KB | Output is correct |
2 | Correct | 44 ms | 47396 KB | Output is correct |
3 | Correct | 44 ms | 47380 KB | Output is correct |
4 | Correct | 45 ms | 47332 KB | Output is correct |
5 | Correct | 45 ms | 47300 KB | Output is correct |
6 | Correct | 45 ms | 47312 KB | Output is correct |
7 | Correct | 44 ms | 47352 KB | Output is correct |
8 | Correct | 46 ms | 47372 KB | Output is correct |
9 | Correct | 44 ms | 47364 KB | Output is correct |
10 | Correct | 44 ms | 47296 KB | Output is correct |
11 | Correct | 45 ms | 47380 KB | Output is correct |
12 | Correct | 45 ms | 47324 KB | Output is correct |
13 | Correct | 44 ms | 47352 KB | Output is correct |
14 | Correct | 44 ms | 47324 KB | Output is correct |
15 | Correct | 44 ms | 47352 KB | Output is correct |
16 | Correct | 44 ms | 47352 KB | Output is correct |
17 | Correct | 44 ms | 47352 KB | Output is correct |
18 | Correct | 44 ms | 47324 KB | Output is correct |
19 | Correct | 44 ms | 47352 KB | Output is correct |
20 | Correct | 43 ms | 47324 KB | Output is correct |
21 | Correct | 45 ms | 47324 KB | Output is correct |
22 | Correct | 44 ms | 47368 KB | Output is correct |
23 | Correct | 45 ms | 47352 KB | Output is correct |
24 | Correct | 45 ms | 47480 KB | Output is correct |
25 | Correct | 45 ms | 47352 KB | Output is correct |
26 | Correct | 45 ms | 47316 KB | Output is correct |
27 | Correct | 52 ms | 49172 KB | Output is correct |
28 | Correct | 51 ms | 48824 KB | Output is correct |
29 | Correct | 57 ms | 49144 KB | Output is correct |
30 | Correct | 53 ms | 48812 KB | Output is correct |
31 | Correct | 68 ms | 49188 KB | Output is correct |
32 | Correct | 59 ms | 48736 KB | Output is correct |
33 | Correct | 53 ms | 49016 KB | Output is correct |
34 | Correct | 52 ms | 48632 KB | Output is correct |
35 | Correct | 56 ms | 49284 KB | Output is correct |
36 | Correct | 56 ms | 49144 KB | Output is correct |
37 | Correct | 55 ms | 49128 KB | Output is correct |
38 | Correct | 57 ms | 49220 KB | Output is correct |
39 | Correct | 55 ms | 49188 KB | Output is correct |
40 | Correct | 56 ms | 49400 KB | Output is correct |
41 | Correct | 55 ms | 49456 KB | Output is correct |
42 | Correct | 54 ms | 49272 KB | Output is correct |
43 | Correct | 54 ms | 49400 KB | Output is correct |
44 | Correct | 54 ms | 49388 KB | Output is correct |
45 | Correct | 55 ms | 49468 KB | Output is correct |
46 | Correct | 55 ms | 49272 KB | Output is correct |
47 | Correct | 54 ms | 49404 KB | Output is correct |
48 | Correct | 194 ms | 69052 KB | Output is correct |
49 | Correct | 205 ms | 69080 KB | Output is correct |
50 | Correct | 198 ms | 68956 KB | Output is correct |
51 | Correct | 202 ms | 68600 KB | Output is correct |
52 | Correct | 186 ms | 65756 KB | Output is correct |
53 | Correct | 175 ms | 67504 KB | Output is correct |
54 | Correct | 175 ms | 65532 KB | Output is correct |
55 | Correct | 163 ms | 65188 KB | Output is correct |
56 | Correct | 169 ms | 64668 KB | Output is correct |
57 | Correct | 988 ms | 115904 KB | Output is correct |
58 | Correct | 776 ms | 94236 KB | Output is correct |
59 | Correct | 757 ms | 94116 KB | Output is correct |
60 | Correct | 850 ms | 99512 KB | Output is correct |
61 | Correct | 827 ms | 99412 KB | Output is correct |
62 | Correct | 426 ms | 81644 KB | Output is correct |
63 | Correct | 567 ms | 87524 KB | Output is correct |
64 | Correct | 544 ms | 84076 KB | Output is correct |
65 | Correct | 276 ms | 73876 KB | Output is correct |