//
// Created by 42kangaroo on 11/09/2023.
//
#include "bits/stdc++.h"
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, c; cin >> n >> c;
vector<int> colorNum(c);
// count number of each color, and adjacent pairs of odd/even
// put these pairs into a vec<vec<int>>
vector<unordered_map<int,int>> adjO(c);
vector<unordered_map<int,int>> adjE(c);
int last = -1;
for (int i = 0; i < n; ++i) {
int a; cin >> a;
--a;
colorNum[a]++;
if (last != -1 && last != a) {
if (i%2) {adjO[last][a]++; adjO[a][last]++;}
else {adjE[last][a]++; adjE[a][last]++;}
}
last = a;
}
// and sort it afterwards by num
vector<int> o(c);
std::iota(o.begin(), o.end(),0);
std::sort(o.begin(), o.end(), [&](int l, int r){return colorNum[l] > colorNum[r];});
// take max of both(odd/even) for each
vector<unordered_map<int,int>> mins(c);
for (int i = 0; i < c; ++i) {
for (auto [k, v]: adjE[i]) {
if (adjO[i].find(k) != adjO[i].end()) {
mins[i][k] = min(adjO[i][k], adjE[i][k]);
}
}
}
// go down with a pointer in the sorted list and check those with connection the max without
for (int i = 0; i < c; ++i) {
int mi = n - colorNum[i];
int j = 0;
if (j < c && o[j] == i) j++;
for (; j < c && mins[i].find(o[j]) != mins[i].end(); ++j) {
mi = min(n - colorNum[i] - colorNum[o[j]] + mins[i][o[j]], mi);
if (j < c - 1 && o[j + 1] == i) ++j;
}
if (j < c) {
mi = min(n - colorNum[i] - colorNum[o[j]], mi);
}
cout << mi<< "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
344 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
348 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
344 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
348 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
5 ms |
344 KB |
Output is correct |
35 |
Correct |
38 ms |
8784 KB |
Output is correct |
36 |
Correct |
36 ms |
8792 KB |
Output is correct |
37 |
Correct |
35 ms |
8784 KB |
Output is correct |
38 |
Correct |
40 ms |
8784 KB |
Output is correct |
39 |
Correct |
38 ms |
8792 KB |
Output is correct |
40 |
Correct |
19 ms |
4952 KB |
Output is correct |
41 |
Correct |
18 ms |
4952 KB |
Output is correct |
42 |
Correct |
17 ms |
3932 KB |
Output is correct |
43 |
Correct |
17 ms |
3928 KB |
Output is correct |
44 |
Correct |
19 ms |
4952 KB |
Output is correct |
45 |
Correct |
18 ms |
4952 KB |
Output is correct |
46 |
Correct |
16 ms |
4184 KB |
Output is correct |
47 |
Correct |
17 ms |
4184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
344 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
348 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
5 ms |
344 KB |
Output is correct |
35 |
Correct |
38 ms |
8784 KB |
Output is correct |
36 |
Correct |
36 ms |
8792 KB |
Output is correct |
37 |
Correct |
35 ms |
8784 KB |
Output is correct |
38 |
Correct |
40 ms |
8784 KB |
Output is correct |
39 |
Correct |
38 ms |
8792 KB |
Output is correct |
40 |
Correct |
19 ms |
4952 KB |
Output is correct |
41 |
Correct |
18 ms |
4952 KB |
Output is correct |
42 |
Correct |
17 ms |
3932 KB |
Output is correct |
43 |
Correct |
17 ms |
3928 KB |
Output is correct |
44 |
Correct |
19 ms |
4952 KB |
Output is correct |
45 |
Correct |
18 ms |
4952 KB |
Output is correct |
46 |
Correct |
16 ms |
4184 KB |
Output is correct |
47 |
Correct |
17 ms |
4184 KB |
Output is correct |
48 |
Correct |
1578 ms |
90192 KB |
Output is correct |
49 |
Correct |
1527 ms |
90316 KB |
Output is correct |
50 |
Correct |
1543 ms |
90196 KB |
Output is correct |
51 |
Correct |
1436 ms |
81700 KB |
Output is correct |
52 |
Correct |
1055 ms |
74276 KB |
Output is correct |
53 |
Correct |
596 ms |
52480 KB |
Output is correct |
54 |
Correct |
414 ms |
41204 KB |
Output is correct |
55 |
Correct |
334 ms |
40060 KB |
Output is correct |
56 |
Correct |
342 ms |
35088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
5 ms |
344 KB |
Output is correct |
28 |
Correct |
5 ms |
344 KB |
Output is correct |
29 |
Correct |
8 ms |
344 KB |
Output is correct |
30 |
Correct |
6 ms |
344 KB |
Output is correct |
31 |
Correct |
5 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
348 KB |
Output is correct |
33 |
Correct |
5 ms |
344 KB |
Output is correct |
34 |
Correct |
5 ms |
344 KB |
Output is correct |
35 |
Correct |
38 ms |
8784 KB |
Output is correct |
36 |
Correct |
36 ms |
8792 KB |
Output is correct |
37 |
Correct |
35 ms |
8784 KB |
Output is correct |
38 |
Correct |
40 ms |
8784 KB |
Output is correct |
39 |
Correct |
38 ms |
8792 KB |
Output is correct |
40 |
Correct |
19 ms |
4952 KB |
Output is correct |
41 |
Correct |
18 ms |
4952 KB |
Output is correct |
42 |
Correct |
17 ms |
3932 KB |
Output is correct |
43 |
Correct |
17 ms |
3928 KB |
Output is correct |
44 |
Correct |
19 ms |
4952 KB |
Output is correct |
45 |
Correct |
18 ms |
4952 KB |
Output is correct |
46 |
Correct |
16 ms |
4184 KB |
Output is correct |
47 |
Correct |
17 ms |
4184 KB |
Output is correct |
48 |
Correct |
1578 ms |
90192 KB |
Output is correct |
49 |
Correct |
1527 ms |
90316 KB |
Output is correct |
50 |
Correct |
1543 ms |
90196 KB |
Output is correct |
51 |
Correct |
1436 ms |
81700 KB |
Output is correct |
52 |
Correct |
1055 ms |
74276 KB |
Output is correct |
53 |
Correct |
596 ms |
52480 KB |
Output is correct |
54 |
Correct |
414 ms |
41204 KB |
Output is correct |
55 |
Correct |
334 ms |
40060 KB |
Output is correct |
56 |
Correct |
342 ms |
35088 KB |
Output is correct |
57 |
Runtime error |
308 ms |
262144 KB |
Execution killed with signal 9 |
58 |
Halted |
0 ms |
0 KB |
- |