#include <bits/stdc++.h>
using namespace std;
const int N = (int) 1e6 + 10;
int n, m;
int a[N];
int ans[N];
int main() {
#ifdef local
freopen("input.txt", "r", stdin);
#endif // local
cin >> n >> m;
if (m == 1) {
cout << 0;
return 0;
}
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= m; i++) {
ans[i] = N;
}
for (int c1 = 1; c1 <= m; c1++) {
for (int c2 = 1; c2 <= m; c2++) {
// c1 | c2
for (int mask = 0; mask < (1 << ((n + 1) / 2)); mask++) {
int cur = 0;
for (int i = 0; i < (n + 1) / 2; i++) {
int x = 2 * (i + 1), y = 2 * (i + 1) + 1;
if ((mask >> i) % 2 == 0) {
cur += (a[x] != c1);
cur += (y <= n && a[y] != c1);
} else {
cur += (a[x] != c2);
cur += (y <= n && a[y] != c2);
}
}
ans[c1] = min(ans[c1], cur);
ans[c2] = min(ans[c2], cur);
}
// c1 | c2
for (int mask = 0; mask < (1 << ((n + 1) / 2)); mask++) {
int cur = 0;
for (int i = 0; i < (n + 1) / 2; i++) {
int x = 2 * (i + 1), y = 2 * (i + 1) - 1;
if ((mask >> i) % 2 == 0) {
cur += (x <= n && a[x] != c1);
cur += (a[y] != c1);
} else {
cur += (x <= n && a[x] != c2);
cur += (a[y] != c2);
}
}
ans[c1] = min(ans[c1], cur);
ans[c2] = min(ans[c2], cur);
}
}
}
for (int i = 1; i <= m; i++) {
cout << ans[i] << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |