#include <bits/stdc++.h>
using namespace std;
const int N = 1000001;
int color[N], tally[N], ans[N];
map<int, int> pairs[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> color[i];
++tally[color[i]];
}
multiset<int> maxi = {0};
for (int i = 1; i <= m; ++i) {
maxi.insert(tally[i]);
ans[i] = INT_MAX;
}
for (int k = 0; k < 2; ++k) {
fill(pairs, pairs + m + 1, map<int, int>());
for (int i = k; i + 2 <= n; i += 2) {
if (color[i] != color[i + 1]) {
++pairs[color[i]][color[i + 1]];
++pairs[color[i + 1]][color[i]];
}
}
for (int i = 1; i <= m; ++i) {
assert(maxi.find(tally[i]) != maxi.end());
maxi.erase(maxi.find(tally[i]));
for (auto [j, k] : pairs[i]) {
assert(maxi.find(tally[j]) != maxi.end());
maxi.erase(maxi.find(tally[j]));
maxi.insert(tally[j] - k);
}
assert(!maxi.empty());
ans[i] = min(ans[i], n - tally[i] - *(--maxi.end()));
for (auto [j, k] : pairs[i]) {
assert(maxi.find(tally[j] - k) != maxi.end());
maxi.erase(maxi.find(tally[j] - k));
maxi.insert(tally[j]);
}
maxi.insert(tally[i]);
}
}
for (int i = 1; i <= m; ++i) {
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47308 KB |
Output is correct |
2 |
Correct |
30 ms |
47220 KB |
Output is correct |
3 |
Correct |
30 ms |
47196 KB |
Output is correct |
4 |
Correct |
28 ms |
47224 KB |
Output is correct |
5 |
Correct |
30 ms |
47248 KB |
Output is correct |
6 |
Correct |
29 ms |
47308 KB |
Output is correct |
7 |
Correct |
30 ms |
47240 KB |
Output is correct |
8 |
Correct |
30 ms |
47180 KB |
Output is correct |
9 |
Correct |
29 ms |
47280 KB |
Output is correct |
10 |
Correct |
30 ms |
47312 KB |
Output is correct |
11 |
Correct |
29 ms |
47292 KB |
Output is correct |
12 |
Correct |
29 ms |
47308 KB |
Output is correct |
13 |
Correct |
29 ms |
47308 KB |
Output is correct |
14 |
Correct |
30 ms |
47308 KB |
Output is correct |
15 |
Correct |
29 ms |
47236 KB |
Output is correct |
16 |
Correct |
30 ms |
47304 KB |
Output is correct |
17 |
Correct |
29 ms |
47308 KB |
Output is correct |
18 |
Correct |
29 ms |
47308 KB |
Output is correct |
19 |
Correct |
29 ms |
47180 KB |
Output is correct |
20 |
Correct |
30 ms |
47300 KB |
Output is correct |
21 |
Correct |
29 ms |
47300 KB |
Output is correct |
22 |
Correct |
30 ms |
47280 KB |
Output is correct |
23 |
Correct |
33 ms |
47172 KB |
Output is correct |
24 |
Correct |
36 ms |
47292 KB |
Output is correct |
25 |
Correct |
30 ms |
47172 KB |
Output is correct |
26 |
Correct |
29 ms |
47228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47308 KB |
Output is correct |
2 |
Correct |
30 ms |
47220 KB |
Output is correct |
3 |
Correct |
30 ms |
47196 KB |
Output is correct |
4 |
Correct |
28 ms |
47224 KB |
Output is correct |
5 |
Correct |
30 ms |
47248 KB |
Output is correct |
6 |
Correct |
29 ms |
47308 KB |
Output is correct |
7 |
Correct |
30 ms |
47240 KB |
Output is correct |
8 |
Correct |
30 ms |
47180 KB |
Output is correct |
9 |
Correct |
29 ms |
47280 KB |
Output is correct |
10 |
Correct |
30 ms |
47312 KB |
Output is correct |
11 |
Correct |
29 ms |
47292 KB |
Output is correct |
12 |
Correct |
29 ms |
47308 KB |
Output is correct |
13 |
Correct |
29 ms |
47308 KB |
Output is correct |
14 |
Correct |
30 ms |
47308 KB |
Output is correct |
15 |
Correct |
29 ms |
47236 KB |
Output is correct |
16 |
Correct |
30 ms |
47304 KB |
Output is correct |
17 |
Correct |
29 ms |
47308 KB |
Output is correct |
18 |
Correct |
29 ms |
47308 KB |
Output is correct |
19 |
Correct |
29 ms |
47180 KB |
Output is correct |
20 |
Correct |
30 ms |
47300 KB |
Output is correct |
21 |
Correct |
29 ms |
47300 KB |
Output is correct |
22 |
Correct |
30 ms |
47280 KB |
Output is correct |
23 |
Correct |
33 ms |
47172 KB |
Output is correct |
24 |
Correct |
36 ms |
47292 KB |
Output is correct |
25 |
Correct |
30 ms |
47172 KB |
Output is correct |
26 |
Correct |
29 ms |
47228 KB |
Output is correct |
27 |
Correct |
39 ms |
47844 KB |
Output is correct |
28 |
Correct |
38 ms |
47832 KB |
Output is correct |
29 |
Correct |
40 ms |
47808 KB |
Output is correct |
30 |
Correct |
39 ms |
47856 KB |
Output is correct |
31 |
Correct |
42 ms |
47952 KB |
Output is correct |
32 |
Correct |
38 ms |
47780 KB |
Output is correct |
33 |
Correct |
41 ms |
47820 KB |
Output is correct |
34 |
Correct |
39 ms |
47808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47308 KB |
Output is correct |
2 |
Correct |
30 ms |
47220 KB |
Output is correct |
3 |
Correct |
30 ms |
47196 KB |
Output is correct |
4 |
Correct |
28 ms |
47224 KB |
Output is correct |
5 |
Correct |
30 ms |
47248 KB |
Output is correct |
6 |
Correct |
29 ms |
47308 KB |
Output is correct |
7 |
Correct |
30 ms |
47240 KB |
Output is correct |
8 |
Correct |
30 ms |
47180 KB |
Output is correct |
9 |
Correct |
29 ms |
47280 KB |
Output is correct |
10 |
Correct |
30 ms |
47312 KB |
Output is correct |
11 |
Correct |
29 ms |
47292 KB |
Output is correct |
12 |
Correct |
29 ms |
47308 KB |
Output is correct |
13 |
Correct |
29 ms |
47308 KB |
Output is correct |
14 |
Correct |
30 ms |
47308 KB |
Output is correct |
15 |
Correct |
29 ms |
47236 KB |
Output is correct |
16 |
Correct |
30 ms |
47304 KB |
Output is correct |
17 |
Correct |
29 ms |
47308 KB |
Output is correct |
18 |
Correct |
29 ms |
47308 KB |
Output is correct |
19 |
Correct |
29 ms |
47180 KB |
Output is correct |
20 |
Correct |
30 ms |
47300 KB |
Output is correct |
21 |
Correct |
29 ms |
47300 KB |
Output is correct |
22 |
Correct |
30 ms |
47280 KB |
Output is correct |
23 |
Correct |
33 ms |
47172 KB |
Output is correct |
24 |
Correct |
36 ms |
47292 KB |
Output is correct |
25 |
Correct |
30 ms |
47172 KB |
Output is correct |
26 |
Correct |
29 ms |
47228 KB |
Output is correct |
27 |
Correct |
39 ms |
47844 KB |
Output is correct |
28 |
Correct |
38 ms |
47832 KB |
Output is correct |
29 |
Correct |
40 ms |
47808 KB |
Output is correct |
30 |
Correct |
39 ms |
47856 KB |
Output is correct |
31 |
Correct |
42 ms |
47952 KB |
Output is correct |
32 |
Correct |
38 ms |
47780 KB |
Output is correct |
33 |
Correct |
41 ms |
47820 KB |
Output is correct |
34 |
Correct |
39 ms |
47808 KB |
Output is correct |
35 |
Correct |
177 ms |
51932 KB |
Output is correct |
36 |
Correct |
175 ms |
52040 KB |
Output is correct |
37 |
Correct |
168 ms |
51884 KB |
Output is correct |
38 |
Correct |
179 ms |
52036 KB |
Output is correct |
39 |
Correct |
175 ms |
51848 KB |
Output is correct |
40 |
Correct |
104 ms |
50116 KB |
Output is correct |
41 |
Correct |
101 ms |
49992 KB |
Output is correct |
42 |
Correct |
87 ms |
49572 KB |
Output is correct |
43 |
Correct |
88 ms |
49484 KB |
Output is correct |
44 |
Correct |
103 ms |
50104 KB |
Output is correct |
45 |
Correct |
103 ms |
50076 KB |
Output is correct |
46 |
Correct |
89 ms |
49676 KB |
Output is correct |
47 |
Correct |
89 ms |
49716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47308 KB |
Output is correct |
2 |
Correct |
30 ms |
47220 KB |
Output is correct |
3 |
Correct |
30 ms |
47196 KB |
Output is correct |
4 |
Correct |
28 ms |
47224 KB |
Output is correct |
5 |
Correct |
30 ms |
47248 KB |
Output is correct |
6 |
Correct |
29 ms |
47308 KB |
Output is correct |
7 |
Correct |
30 ms |
47240 KB |
Output is correct |
8 |
Correct |
30 ms |
47180 KB |
Output is correct |
9 |
Correct |
29 ms |
47280 KB |
Output is correct |
10 |
Correct |
30 ms |
47312 KB |
Output is correct |
11 |
Correct |
29 ms |
47292 KB |
Output is correct |
12 |
Correct |
29 ms |
47308 KB |
Output is correct |
13 |
Correct |
29 ms |
47308 KB |
Output is correct |
14 |
Correct |
30 ms |
47308 KB |
Output is correct |
15 |
Correct |
29 ms |
47236 KB |
Output is correct |
16 |
Correct |
30 ms |
47304 KB |
Output is correct |
17 |
Correct |
29 ms |
47308 KB |
Output is correct |
18 |
Correct |
29 ms |
47308 KB |
Output is correct |
19 |
Correct |
29 ms |
47180 KB |
Output is correct |
20 |
Correct |
30 ms |
47300 KB |
Output is correct |
21 |
Correct |
29 ms |
47300 KB |
Output is correct |
22 |
Correct |
30 ms |
47280 KB |
Output is correct |
23 |
Correct |
33 ms |
47172 KB |
Output is correct |
24 |
Correct |
36 ms |
47292 KB |
Output is correct |
25 |
Correct |
30 ms |
47172 KB |
Output is correct |
26 |
Correct |
29 ms |
47228 KB |
Output is correct |
27 |
Correct |
39 ms |
47844 KB |
Output is correct |
28 |
Correct |
38 ms |
47832 KB |
Output is correct |
29 |
Correct |
40 ms |
47808 KB |
Output is correct |
30 |
Correct |
39 ms |
47856 KB |
Output is correct |
31 |
Correct |
42 ms |
47952 KB |
Output is correct |
32 |
Correct |
38 ms |
47780 KB |
Output is correct |
33 |
Correct |
41 ms |
47820 KB |
Output is correct |
34 |
Correct |
39 ms |
47808 KB |
Output is correct |
35 |
Correct |
177 ms |
51932 KB |
Output is correct |
36 |
Correct |
175 ms |
52040 KB |
Output is correct |
37 |
Correct |
168 ms |
51884 KB |
Output is correct |
38 |
Correct |
179 ms |
52036 KB |
Output is correct |
39 |
Correct |
175 ms |
51848 KB |
Output is correct |
40 |
Correct |
104 ms |
50116 KB |
Output is correct |
41 |
Correct |
101 ms |
49992 KB |
Output is correct |
42 |
Correct |
87 ms |
49572 KB |
Output is correct |
43 |
Correct |
88 ms |
49484 KB |
Output is correct |
44 |
Correct |
103 ms |
50104 KB |
Output is correct |
45 |
Correct |
103 ms |
50076 KB |
Output is correct |
46 |
Correct |
89 ms |
49676 KB |
Output is correct |
47 |
Correct |
89 ms |
49716 KB |
Output is correct |
48 |
Execution timed out |
2586 ms |
96152 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47308 KB |
Output is correct |
2 |
Correct |
30 ms |
47220 KB |
Output is correct |
3 |
Correct |
30 ms |
47196 KB |
Output is correct |
4 |
Correct |
28 ms |
47224 KB |
Output is correct |
5 |
Correct |
30 ms |
47248 KB |
Output is correct |
6 |
Correct |
29 ms |
47308 KB |
Output is correct |
7 |
Correct |
30 ms |
47240 KB |
Output is correct |
8 |
Correct |
30 ms |
47180 KB |
Output is correct |
9 |
Correct |
29 ms |
47280 KB |
Output is correct |
10 |
Correct |
30 ms |
47312 KB |
Output is correct |
11 |
Correct |
29 ms |
47292 KB |
Output is correct |
12 |
Correct |
29 ms |
47308 KB |
Output is correct |
13 |
Correct |
29 ms |
47308 KB |
Output is correct |
14 |
Correct |
30 ms |
47308 KB |
Output is correct |
15 |
Correct |
29 ms |
47236 KB |
Output is correct |
16 |
Correct |
30 ms |
47304 KB |
Output is correct |
17 |
Correct |
29 ms |
47308 KB |
Output is correct |
18 |
Correct |
29 ms |
47308 KB |
Output is correct |
19 |
Correct |
29 ms |
47180 KB |
Output is correct |
20 |
Correct |
30 ms |
47300 KB |
Output is correct |
21 |
Correct |
29 ms |
47300 KB |
Output is correct |
22 |
Correct |
30 ms |
47280 KB |
Output is correct |
23 |
Correct |
33 ms |
47172 KB |
Output is correct |
24 |
Correct |
36 ms |
47292 KB |
Output is correct |
25 |
Correct |
30 ms |
47172 KB |
Output is correct |
26 |
Correct |
29 ms |
47228 KB |
Output is correct |
27 |
Correct |
39 ms |
47844 KB |
Output is correct |
28 |
Correct |
38 ms |
47832 KB |
Output is correct |
29 |
Correct |
40 ms |
47808 KB |
Output is correct |
30 |
Correct |
39 ms |
47856 KB |
Output is correct |
31 |
Correct |
42 ms |
47952 KB |
Output is correct |
32 |
Correct |
38 ms |
47780 KB |
Output is correct |
33 |
Correct |
41 ms |
47820 KB |
Output is correct |
34 |
Correct |
39 ms |
47808 KB |
Output is correct |
35 |
Correct |
177 ms |
51932 KB |
Output is correct |
36 |
Correct |
175 ms |
52040 KB |
Output is correct |
37 |
Correct |
168 ms |
51884 KB |
Output is correct |
38 |
Correct |
179 ms |
52036 KB |
Output is correct |
39 |
Correct |
175 ms |
51848 KB |
Output is correct |
40 |
Correct |
104 ms |
50116 KB |
Output is correct |
41 |
Correct |
101 ms |
49992 KB |
Output is correct |
42 |
Correct |
87 ms |
49572 KB |
Output is correct |
43 |
Correct |
88 ms |
49484 KB |
Output is correct |
44 |
Correct |
103 ms |
50104 KB |
Output is correct |
45 |
Correct |
103 ms |
50076 KB |
Output is correct |
46 |
Correct |
89 ms |
49676 KB |
Output is correct |
47 |
Correct |
89 ms |
49716 KB |
Output is correct |
48 |
Execution timed out |
2586 ms |
96152 KB |
Time limit exceeded |
49 |
Halted |
0 ms |
0 KB |
- |