from collections import Counter
import sys as sus
input = sus.stdin.readline
n, m = map(int, input().split())
c = list(range(1, m + 1))
c = list(map(int, input().split()))
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
for v in odd:
odd[v] = min(odd[v], eve[v])
del eve
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 = bl
#print(bl, br)
#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 |
39 ms |
18604 KB |
Output is correct |
2 |
Correct |
40 ms |
18620 KB |
Output is correct |
3 |
Correct |
43 ms |
18592 KB |
Output is correct |
4 |
Correct |
42 ms |
18560 KB |
Output is correct |
5 |
Correct |
40 ms |
18580 KB |
Output is correct |
6 |
Correct |
44 ms |
18596 KB |
Output is correct |
7 |
Correct |
42 ms |
18652 KB |
Output is correct |
8 |
Correct |
46 ms |
18636 KB |
Output is correct |
9 |
Correct |
50 ms |
18576 KB |
Output is correct |
10 |
Correct |
53 ms |
18644 KB |
Output is correct |
11 |
Correct |
42 ms |
18648 KB |
Output is correct |
12 |
Correct |
40 ms |
18612 KB |
Output is correct |
13 |
Correct |
41 ms |
18732 KB |
Output is correct |
14 |
Correct |
40 ms |
18648 KB |
Output is correct |
15 |
Correct |
41 ms |
18548 KB |
Output is correct |
16 |
Correct |
43 ms |
18548 KB |
Output is correct |
17 |
Correct |
43 ms |
18652 KB |
Output is correct |
18 |
Correct |
39 ms |
18588 KB |
Output is correct |
19 |
Correct |
42 ms |
18604 KB |
Output is correct |
20 |
Correct |
42 ms |
18644 KB |
Output is correct |
21 |
Correct |
42 ms |
18636 KB |
Output is correct |
22 |
Correct |
39 ms |
18560 KB |
Output is correct |
23 |
Correct |
40 ms |
18548 KB |
Output is correct |
24 |
Correct |
46 ms |
18628 KB |
Output is correct |
25 |
Correct |
41 ms |
18612 KB |
Output is correct |
26 |
Correct |
41 ms |
18632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
18604 KB |
Output is correct |
2 |
Correct |
40 ms |
18620 KB |
Output is correct |
3 |
Correct |
43 ms |
18592 KB |
Output is correct |
4 |
Correct |
42 ms |
18560 KB |
Output is correct |
5 |
Correct |
40 ms |
18580 KB |
Output is correct |
6 |
Correct |
44 ms |
18596 KB |
Output is correct |
7 |
Correct |
42 ms |
18652 KB |
Output is correct |
8 |
Correct |
46 ms |
18636 KB |
Output is correct |
9 |
Correct |
50 ms |
18576 KB |
Output is correct |
10 |
Correct |
53 ms |
18644 KB |
Output is correct |
11 |
Correct |
42 ms |
18648 KB |
Output is correct |
12 |
Correct |
40 ms |
18612 KB |
Output is correct |
13 |
Correct |
41 ms |
18732 KB |
Output is correct |
14 |
Correct |
40 ms |
18648 KB |
Output is correct |
15 |
Correct |
41 ms |
18548 KB |
Output is correct |
16 |
Correct |
43 ms |
18548 KB |
Output is correct |
17 |
Correct |
43 ms |
18652 KB |
Output is correct |
18 |
Correct |
39 ms |
18588 KB |
Output is correct |
19 |
Correct |
42 ms |
18604 KB |
Output is correct |
20 |
Correct |
42 ms |
18644 KB |
Output is correct |
21 |
Correct |
42 ms |
18636 KB |
Output is correct |
22 |
Correct |
39 ms |
18560 KB |
Output is correct |
23 |
Correct |
40 ms |
18548 KB |
Output is correct |
24 |
Correct |
46 ms |
18628 KB |
Output is correct |
25 |
Correct |
41 ms |
18612 KB |
Output is correct |
26 |
Correct |
41 ms |
18632 KB |
Output is correct |
27 |
Correct |
97 ms |
30384 KB |
Output is correct |
28 |
Correct |
85 ms |
30480 KB |
Output is correct |
29 |
Correct |
86 ms |
30440 KB |
Output is correct |
30 |
Correct |
83 ms |
30444 KB |
Output is correct |
31 |
Correct |
87 ms |
30428 KB |
Output is correct |
32 |
Correct |
95 ms |
30328 KB |
Output is correct |
33 |
Correct |
88 ms |
30356 KB |
Output is correct |
34 |
Correct |
84 ms |
30416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
18604 KB |
Output is correct |
2 |
Correct |
40 ms |
18620 KB |
Output is correct |
3 |
Correct |
43 ms |
18592 KB |
Output is correct |
4 |
Correct |
42 ms |
18560 KB |
Output is correct |
5 |
Correct |
40 ms |
18580 KB |
Output is correct |
6 |
Correct |
44 ms |
18596 KB |
Output is correct |
7 |
Correct |
42 ms |
18652 KB |
Output is correct |
8 |
Correct |
46 ms |
18636 KB |
Output is correct |
9 |
Correct |
50 ms |
18576 KB |
Output is correct |
10 |
Correct |
53 ms |
18644 KB |
Output is correct |
11 |
Correct |
42 ms |
18648 KB |
Output is correct |
12 |
Correct |
40 ms |
18612 KB |
Output is correct |
13 |
Correct |
41 ms |
18732 KB |
Output is correct |
14 |
Correct |
40 ms |
18648 KB |
Output is correct |
15 |
Correct |
41 ms |
18548 KB |
Output is correct |
16 |
Correct |
43 ms |
18548 KB |
Output is correct |
17 |
Correct |
43 ms |
18652 KB |
Output is correct |
18 |
Correct |
39 ms |
18588 KB |
Output is correct |
19 |
Correct |
42 ms |
18604 KB |
Output is correct |
20 |
Correct |
42 ms |
18644 KB |
Output is correct |
21 |
Correct |
42 ms |
18636 KB |
Output is correct |
22 |
Correct |
39 ms |
18560 KB |
Output is correct |
23 |
Correct |
40 ms |
18548 KB |
Output is correct |
24 |
Correct |
46 ms |
18628 KB |
Output is correct |
25 |
Correct |
41 ms |
18612 KB |
Output is correct |
26 |
Correct |
41 ms |
18632 KB |
Output is correct |
27 |
Correct |
97 ms |
30384 KB |
Output is correct |
28 |
Correct |
85 ms |
30480 KB |
Output is correct |
29 |
Correct |
86 ms |
30440 KB |
Output is correct |
30 |
Correct |
83 ms |
30444 KB |
Output is correct |
31 |
Correct |
87 ms |
30428 KB |
Output is correct |
32 |
Correct |
95 ms |
30328 KB |
Output is correct |
33 |
Correct |
88 ms |
30356 KB |
Output is correct |
34 |
Correct |
84 ms |
30416 KB |
Output is correct |
35 |
Correct |
127 ms |
35168 KB |
Output is correct |
36 |
Correct |
139 ms |
35932 KB |
Output is correct |
37 |
Correct |
122 ms |
35160 KB |
Output is correct |
38 |
Correct |
123 ms |
35272 KB |
Output is correct |
39 |
Correct |
133 ms |
35268 KB |
Output is correct |
40 |
Correct |
139 ms |
35044 KB |
Output is correct |
41 |
Correct |
142 ms |
34796 KB |
Output is correct |
42 |
Correct |
127 ms |
32356 KB |
Output is correct |
43 |
Correct |
125 ms |
33632 KB |
Output is correct |
44 |
Correct |
142 ms |
36108 KB |
Output is correct |
45 |
Correct |
138 ms |
35152 KB |
Output is correct |
46 |
Correct |
127 ms |
33024 KB |
Output is correct |
47 |
Correct |
127 ms |
32160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
18604 KB |
Output is correct |
2 |
Correct |
40 ms |
18620 KB |
Output is correct |
3 |
Correct |
43 ms |
18592 KB |
Output is correct |
4 |
Correct |
42 ms |
18560 KB |
Output is correct |
5 |
Correct |
40 ms |
18580 KB |
Output is correct |
6 |
Correct |
44 ms |
18596 KB |
Output is correct |
7 |
Correct |
42 ms |
18652 KB |
Output is correct |
8 |
Correct |
46 ms |
18636 KB |
Output is correct |
9 |
Correct |
50 ms |
18576 KB |
Output is correct |
10 |
Correct |
53 ms |
18644 KB |
Output is correct |
11 |
Correct |
42 ms |
18648 KB |
Output is correct |
12 |
Correct |
40 ms |
18612 KB |
Output is correct |
13 |
Correct |
41 ms |
18732 KB |
Output is correct |
14 |
Correct |
40 ms |
18648 KB |
Output is correct |
15 |
Correct |
41 ms |
18548 KB |
Output is correct |
16 |
Correct |
43 ms |
18548 KB |
Output is correct |
17 |
Correct |
43 ms |
18652 KB |
Output is correct |
18 |
Correct |
39 ms |
18588 KB |
Output is correct |
19 |
Correct |
42 ms |
18604 KB |
Output is correct |
20 |
Correct |
42 ms |
18644 KB |
Output is correct |
21 |
Correct |
42 ms |
18636 KB |
Output is correct |
22 |
Correct |
39 ms |
18560 KB |
Output is correct |
23 |
Correct |
40 ms |
18548 KB |
Output is correct |
24 |
Correct |
46 ms |
18628 KB |
Output is correct |
25 |
Correct |
41 ms |
18612 KB |
Output is correct |
26 |
Correct |
41 ms |
18632 KB |
Output is correct |
27 |
Correct |
97 ms |
30384 KB |
Output is correct |
28 |
Correct |
85 ms |
30480 KB |
Output is correct |
29 |
Correct |
86 ms |
30440 KB |
Output is correct |
30 |
Correct |
83 ms |
30444 KB |
Output is correct |
31 |
Correct |
87 ms |
30428 KB |
Output is correct |
32 |
Correct |
95 ms |
30328 KB |
Output is correct |
33 |
Correct |
88 ms |
30356 KB |
Output is correct |
34 |
Correct |
84 ms |
30416 KB |
Output is correct |
35 |
Correct |
127 ms |
35168 KB |
Output is correct |
36 |
Correct |
139 ms |
35932 KB |
Output is correct |
37 |
Correct |
122 ms |
35160 KB |
Output is correct |
38 |
Correct |
123 ms |
35272 KB |
Output is correct |
39 |
Correct |
133 ms |
35268 KB |
Output is correct |
40 |
Correct |
139 ms |
35044 KB |
Output is correct |
41 |
Correct |
142 ms |
34796 KB |
Output is correct |
42 |
Correct |
127 ms |
32356 KB |
Output is correct |
43 |
Correct |
125 ms |
33632 KB |
Output is correct |
44 |
Correct |
142 ms |
36108 KB |
Output is correct |
45 |
Correct |
138 ms |
35152 KB |
Output is correct |
46 |
Correct |
127 ms |
33024 KB |
Output is correct |
47 |
Correct |
127 ms |
32160 KB |
Output is correct |
48 |
Correct |
801 ms |
125252 KB |
Output is correct |
49 |
Correct |
775 ms |
125952 KB |
Output is correct |
50 |
Correct |
786 ms |
124844 KB |
Output is correct |
51 |
Correct |
807 ms |
121620 KB |
Output is correct |
52 |
Correct |
783 ms |
138728 KB |
Output is correct |
53 |
Correct |
586 ms |
121892 KB |
Output is correct |
54 |
Correct |
564 ms |
121840 KB |
Output is correct |
55 |
Correct |
587 ms |
121888 KB |
Output is correct |
56 |
Correct |
530 ms |
121948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
39 ms |
18604 KB |
Output is correct |
2 |
Correct |
40 ms |
18620 KB |
Output is correct |
3 |
Correct |
43 ms |
18592 KB |
Output is correct |
4 |
Correct |
42 ms |
18560 KB |
Output is correct |
5 |
Correct |
40 ms |
18580 KB |
Output is correct |
6 |
Correct |
44 ms |
18596 KB |
Output is correct |
7 |
Correct |
42 ms |
18652 KB |
Output is correct |
8 |
Correct |
46 ms |
18636 KB |
Output is correct |
9 |
Correct |
50 ms |
18576 KB |
Output is correct |
10 |
Correct |
53 ms |
18644 KB |
Output is correct |
11 |
Correct |
42 ms |
18648 KB |
Output is correct |
12 |
Correct |
40 ms |
18612 KB |
Output is correct |
13 |
Correct |
41 ms |
18732 KB |
Output is correct |
14 |
Correct |
40 ms |
18648 KB |
Output is correct |
15 |
Correct |
41 ms |
18548 KB |
Output is correct |
16 |
Correct |
43 ms |
18548 KB |
Output is correct |
17 |
Correct |
43 ms |
18652 KB |
Output is correct |
18 |
Correct |
39 ms |
18588 KB |
Output is correct |
19 |
Correct |
42 ms |
18604 KB |
Output is correct |
20 |
Correct |
42 ms |
18644 KB |
Output is correct |
21 |
Correct |
42 ms |
18636 KB |
Output is correct |
22 |
Correct |
39 ms |
18560 KB |
Output is correct |
23 |
Correct |
40 ms |
18548 KB |
Output is correct |
24 |
Correct |
46 ms |
18628 KB |
Output is correct |
25 |
Correct |
41 ms |
18612 KB |
Output is correct |
26 |
Correct |
41 ms |
18632 KB |
Output is correct |
27 |
Correct |
97 ms |
30384 KB |
Output is correct |
28 |
Correct |
85 ms |
30480 KB |
Output is correct |
29 |
Correct |
86 ms |
30440 KB |
Output is correct |
30 |
Correct |
83 ms |
30444 KB |
Output is correct |
31 |
Correct |
87 ms |
30428 KB |
Output is correct |
32 |
Correct |
95 ms |
30328 KB |
Output is correct |
33 |
Correct |
88 ms |
30356 KB |
Output is correct |
34 |
Correct |
84 ms |
30416 KB |
Output is correct |
35 |
Correct |
127 ms |
35168 KB |
Output is correct |
36 |
Correct |
139 ms |
35932 KB |
Output is correct |
37 |
Correct |
122 ms |
35160 KB |
Output is correct |
38 |
Correct |
123 ms |
35272 KB |
Output is correct |
39 |
Correct |
133 ms |
35268 KB |
Output is correct |
40 |
Correct |
139 ms |
35044 KB |
Output is correct |
41 |
Correct |
142 ms |
34796 KB |
Output is correct |
42 |
Correct |
127 ms |
32356 KB |
Output is correct |
43 |
Correct |
125 ms |
33632 KB |
Output is correct |
44 |
Correct |
142 ms |
36108 KB |
Output is correct |
45 |
Correct |
138 ms |
35152 KB |
Output is correct |
46 |
Correct |
127 ms |
33024 KB |
Output is correct |
47 |
Correct |
127 ms |
32160 KB |
Output is correct |
48 |
Correct |
801 ms |
125252 KB |
Output is correct |
49 |
Correct |
775 ms |
125952 KB |
Output is correct |
50 |
Correct |
786 ms |
124844 KB |
Output is correct |
51 |
Correct |
807 ms |
121620 KB |
Output is correct |
52 |
Correct |
783 ms |
138728 KB |
Output is correct |
53 |
Correct |
586 ms |
121892 KB |
Output is correct |
54 |
Correct |
564 ms |
121840 KB |
Output is correct |
55 |
Correct |
587 ms |
121888 KB |
Output is correct |
56 |
Correct |
530 ms |
121948 KB |
Output is correct |
57 |
Runtime error |
1422 ms |
262144 KB |
Execution killed with signal 9 |
58 |
Halted |
0 ms |
0 KB |
- |