답안 #590334

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
590334 2022-07-05T20:49:51 Z dnialh Rope (JOI17_rope) PyPy 3
80 / 100
1520 ms 262268 KB
from collections import Counter

import sys as sus
input = sus.stdin.readline

n, m = map(int, input().split())
c = list(map(int, input().split()))
#c = list(range(1, m + 1))

ct = Counter(c)
ctl = [0] * (m + 1)
for i in range(1, m + 1):
    ctl[i] = ct[i]
o = ct.most_common()

del ct

odd = Counter()
eve = Counter()

for i in range(n - 1):
    s = min(c[i], c[i + 1])
    b = max(c[i], c[i + 1])
    if i % 2:
        odd[(s << 20) |  b] += 1
    else:
        eve[(s << 20) |  b] += 1

out = []
for i in range(1, m + 1):
    res = 0
    for v, vc in o:
        if v == i:
            continue

        bl = odd[(i << 20) | v] + odd[v << 20 | i]
        br = eve[(i << 20) | v] + eve[v << 20 | i]

        bad = min(bl, br)

        res = max(res, vc - bad)

        if bad == 0:
            break
    out.append(n - res - ctl[i])
print('\n'.join(map(str, out)))
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 18604 KB Output is correct
2 Correct 42 ms 18596 KB Output is correct
3 Correct 44 ms 18572 KB Output is correct
4 Correct 44 ms 18580 KB Output is correct
5 Correct 41 ms 18620 KB Output is correct
6 Correct 41 ms 18620 KB Output is correct
7 Correct 45 ms 18544 KB Output is correct
8 Correct 44 ms 18528 KB Output is correct
9 Correct 42 ms 18648 KB Output is correct
10 Correct 41 ms 18580 KB Output is correct
11 Correct 42 ms 18572 KB Output is correct
12 Correct 40 ms 18564 KB Output is correct
13 Correct 41 ms 18600 KB Output is correct
14 Correct 40 ms 18564 KB Output is correct
15 Correct 44 ms 18760 KB Output is correct
16 Correct 41 ms 18524 KB Output is correct
17 Correct 43 ms 18588 KB Output is correct
18 Correct 39 ms 18544 KB Output is correct
19 Correct 40 ms 18636 KB Output is correct
20 Correct 41 ms 18628 KB Output is correct
21 Correct 42 ms 18604 KB Output is correct
22 Correct 40 ms 18620 KB Output is correct
23 Correct 41 ms 18644 KB Output is correct
24 Correct 40 ms 18524 KB Output is correct
25 Correct 46 ms 18652 KB Output is correct
26 Correct 40 ms 18648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 18604 KB Output is correct
2 Correct 42 ms 18596 KB Output is correct
3 Correct 44 ms 18572 KB Output is correct
4 Correct 44 ms 18580 KB Output is correct
5 Correct 41 ms 18620 KB Output is correct
6 Correct 41 ms 18620 KB Output is correct
7 Correct 45 ms 18544 KB Output is correct
8 Correct 44 ms 18528 KB Output is correct
9 Correct 42 ms 18648 KB Output is correct
10 Correct 41 ms 18580 KB Output is correct
11 Correct 42 ms 18572 KB Output is correct
12 Correct 40 ms 18564 KB Output is correct
13 Correct 41 ms 18600 KB Output is correct
14 Correct 40 ms 18564 KB Output is correct
15 Correct 44 ms 18760 KB Output is correct
16 Correct 41 ms 18524 KB Output is correct
17 Correct 43 ms 18588 KB Output is correct
18 Correct 39 ms 18544 KB Output is correct
19 Correct 40 ms 18636 KB Output is correct
20 Correct 41 ms 18628 KB Output is correct
21 Correct 42 ms 18604 KB Output is correct
22 Correct 40 ms 18620 KB Output is correct
23 Correct 41 ms 18644 KB Output is correct
24 Correct 40 ms 18524 KB Output is correct
25 Correct 46 ms 18652 KB Output is correct
26 Correct 40 ms 18648 KB Output is correct
27 Correct 92 ms 30440 KB Output is correct
28 Correct 90 ms 30336 KB Output is correct
29 Correct 91 ms 30400 KB Output is correct
30 Correct 94 ms 30376 KB Output is correct
31 Correct 104 ms 30420 KB Output is correct
32 Correct 97 ms 30508 KB Output is correct
33 Correct 87 ms 30436 KB Output is correct
34 Correct 84 ms 30456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 18604 KB Output is correct
2 Correct 42 ms 18596 KB Output is correct
3 Correct 44 ms 18572 KB Output is correct
4 Correct 44 ms 18580 KB Output is correct
5 Correct 41 ms 18620 KB Output is correct
6 Correct 41 ms 18620 KB Output is correct
7 Correct 45 ms 18544 KB Output is correct
8 Correct 44 ms 18528 KB Output is correct
9 Correct 42 ms 18648 KB Output is correct
10 Correct 41 ms 18580 KB Output is correct
11 Correct 42 ms 18572 KB Output is correct
12 Correct 40 ms 18564 KB Output is correct
13 Correct 41 ms 18600 KB Output is correct
14 Correct 40 ms 18564 KB Output is correct
15 Correct 44 ms 18760 KB Output is correct
16 Correct 41 ms 18524 KB Output is correct
17 Correct 43 ms 18588 KB Output is correct
18 Correct 39 ms 18544 KB Output is correct
19 Correct 40 ms 18636 KB Output is correct
20 Correct 41 ms 18628 KB Output is correct
21 Correct 42 ms 18604 KB Output is correct
22 Correct 40 ms 18620 KB Output is correct
23 Correct 41 ms 18644 KB Output is correct
24 Correct 40 ms 18524 KB Output is correct
25 Correct 46 ms 18652 KB Output is correct
26 Correct 40 ms 18648 KB Output is correct
27 Correct 92 ms 30440 KB Output is correct
28 Correct 90 ms 30336 KB Output is correct
29 Correct 91 ms 30400 KB Output is correct
30 Correct 94 ms 30376 KB Output is correct
31 Correct 104 ms 30420 KB Output is correct
32 Correct 97 ms 30508 KB Output is correct
33 Correct 87 ms 30436 KB Output is correct
34 Correct 84 ms 30456 KB Output is correct
35 Correct 108 ms 35092 KB Output is correct
36 Correct 122 ms 35620 KB Output is correct
37 Correct 126 ms 35116 KB Output is correct
38 Correct 117 ms 35592 KB Output is correct
39 Correct 115 ms 35316 KB Output is correct
40 Correct 134 ms 35304 KB Output is correct
41 Correct 126 ms 35280 KB Output is correct
42 Correct 123 ms 32016 KB Output is correct
43 Correct 156 ms 33472 KB Output is correct
44 Correct 132 ms 36024 KB Output is correct
45 Correct 125 ms 35200 KB Output is correct
46 Correct 126 ms 32308 KB Output is correct
47 Correct 122 ms 32188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 18604 KB Output is correct
2 Correct 42 ms 18596 KB Output is correct
3 Correct 44 ms 18572 KB Output is correct
4 Correct 44 ms 18580 KB Output is correct
5 Correct 41 ms 18620 KB Output is correct
6 Correct 41 ms 18620 KB Output is correct
7 Correct 45 ms 18544 KB Output is correct
8 Correct 44 ms 18528 KB Output is correct
9 Correct 42 ms 18648 KB Output is correct
10 Correct 41 ms 18580 KB Output is correct
11 Correct 42 ms 18572 KB Output is correct
12 Correct 40 ms 18564 KB Output is correct
13 Correct 41 ms 18600 KB Output is correct
14 Correct 40 ms 18564 KB Output is correct
15 Correct 44 ms 18760 KB Output is correct
16 Correct 41 ms 18524 KB Output is correct
17 Correct 43 ms 18588 KB Output is correct
18 Correct 39 ms 18544 KB Output is correct
19 Correct 40 ms 18636 KB Output is correct
20 Correct 41 ms 18628 KB Output is correct
21 Correct 42 ms 18604 KB Output is correct
22 Correct 40 ms 18620 KB Output is correct
23 Correct 41 ms 18644 KB Output is correct
24 Correct 40 ms 18524 KB Output is correct
25 Correct 46 ms 18652 KB Output is correct
26 Correct 40 ms 18648 KB Output is correct
27 Correct 92 ms 30440 KB Output is correct
28 Correct 90 ms 30336 KB Output is correct
29 Correct 91 ms 30400 KB Output is correct
30 Correct 94 ms 30376 KB Output is correct
31 Correct 104 ms 30420 KB Output is correct
32 Correct 97 ms 30508 KB Output is correct
33 Correct 87 ms 30436 KB Output is correct
34 Correct 84 ms 30456 KB Output is correct
35 Correct 108 ms 35092 KB Output is correct
36 Correct 122 ms 35620 KB Output is correct
37 Correct 126 ms 35116 KB Output is correct
38 Correct 117 ms 35592 KB Output is correct
39 Correct 115 ms 35316 KB Output is correct
40 Correct 134 ms 35304 KB Output is correct
41 Correct 126 ms 35280 KB Output is correct
42 Correct 123 ms 32016 KB Output is correct
43 Correct 156 ms 33472 KB Output is correct
44 Correct 132 ms 36024 KB Output is correct
45 Correct 125 ms 35200 KB Output is correct
46 Correct 126 ms 32308 KB Output is correct
47 Correct 122 ms 32188 KB Output is correct
48 Correct 706 ms 157740 KB Output is correct
49 Correct 714 ms 150692 KB Output is correct
50 Correct 646 ms 152260 KB Output is correct
51 Correct 713 ms 148548 KB Output is correct
52 Correct 732 ms 138544 KB Output is correct
53 Correct 670 ms 133760 KB Output is correct
54 Correct 597 ms 129744 KB Output is correct
55 Correct 606 ms 129456 KB Output is correct
56 Correct 629 ms 128852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 18604 KB Output is correct
2 Correct 42 ms 18596 KB Output is correct
3 Correct 44 ms 18572 KB Output is correct
4 Correct 44 ms 18580 KB Output is correct
5 Correct 41 ms 18620 KB Output is correct
6 Correct 41 ms 18620 KB Output is correct
7 Correct 45 ms 18544 KB Output is correct
8 Correct 44 ms 18528 KB Output is correct
9 Correct 42 ms 18648 KB Output is correct
10 Correct 41 ms 18580 KB Output is correct
11 Correct 42 ms 18572 KB Output is correct
12 Correct 40 ms 18564 KB Output is correct
13 Correct 41 ms 18600 KB Output is correct
14 Correct 40 ms 18564 KB Output is correct
15 Correct 44 ms 18760 KB Output is correct
16 Correct 41 ms 18524 KB Output is correct
17 Correct 43 ms 18588 KB Output is correct
18 Correct 39 ms 18544 KB Output is correct
19 Correct 40 ms 18636 KB Output is correct
20 Correct 41 ms 18628 KB Output is correct
21 Correct 42 ms 18604 KB Output is correct
22 Correct 40 ms 18620 KB Output is correct
23 Correct 41 ms 18644 KB Output is correct
24 Correct 40 ms 18524 KB Output is correct
25 Correct 46 ms 18652 KB Output is correct
26 Correct 40 ms 18648 KB Output is correct
27 Correct 92 ms 30440 KB Output is correct
28 Correct 90 ms 30336 KB Output is correct
29 Correct 91 ms 30400 KB Output is correct
30 Correct 94 ms 30376 KB Output is correct
31 Correct 104 ms 30420 KB Output is correct
32 Correct 97 ms 30508 KB Output is correct
33 Correct 87 ms 30436 KB Output is correct
34 Correct 84 ms 30456 KB Output is correct
35 Correct 108 ms 35092 KB Output is correct
36 Correct 122 ms 35620 KB Output is correct
37 Correct 126 ms 35116 KB Output is correct
38 Correct 117 ms 35592 KB Output is correct
39 Correct 115 ms 35316 KB Output is correct
40 Correct 134 ms 35304 KB Output is correct
41 Correct 126 ms 35280 KB Output is correct
42 Correct 123 ms 32016 KB Output is correct
43 Correct 156 ms 33472 KB Output is correct
44 Correct 132 ms 36024 KB Output is correct
45 Correct 125 ms 35200 KB Output is correct
46 Correct 126 ms 32308 KB Output is correct
47 Correct 122 ms 32188 KB Output is correct
48 Correct 706 ms 157740 KB Output is correct
49 Correct 714 ms 150692 KB Output is correct
50 Correct 646 ms 152260 KB Output is correct
51 Correct 713 ms 148548 KB Output is correct
52 Correct 732 ms 138544 KB Output is correct
53 Correct 670 ms 133760 KB Output is correct
54 Correct 597 ms 129744 KB Output is correct
55 Correct 606 ms 129456 KB Output is correct
56 Correct 629 ms 128852 KB Output is correct
57 Runtime error 1520 ms 262268 KB Execution killed with signal 9
58 Halted 0 ms 0 KB -