#include "bits/stdc++.h"
using namespace std;
#define debug(x) cout << #x << " : " << x << "\n" ;
#define all(v) v.begin() , v.end()
#define printv(x) {for(auto &ele : x) cout << ele << " " ; cout << "\n" ;}
#define print(x) { cout << x << "\n" ;}
#define print2(x,y) { cout << x << " " << y << "\n" ;}
#define print3(x,y,z) { cout << x << " " << y << " " << z << "\n" ;}
#define kill(x) {cout << x << "\n"; return ;}
#define rep(i, a, n) for(int i = a; i < (int) n ; i++)
#define vvi vector<vector<int>>
#define vi vector<int>
#define vpii vector<pair<int,int>>
#define pii pair<int,int>
#define nl cout << "\n"
#define mp(a, b) make_pair(a, b)
constexpr int mod = 1e9 + 7;
void solve() {
int N, M;
cin >> N >> M;
vi C(N);
vvi cnt(2, vi(M + 1, 0));
rep(i, 0, N) {
cin >> C[i];
cnt[i % 2][C[i]]++;
}
vvi mx = cnt;
rep(i, 0, N - 1) {
int c1 = C[i];
int c2 = C[i+1];
if (c1 == c2) continue;
int p = i % 2;
mx[1 - p][c1] = max(mx[1 - p][c1], cnt[1 - p][c1] + 1);
mx[p][c2] = max(mx[p][c2], cnt[p][c2] + 1);
}
int sz0 = (N + 1) / 2;
int sz1 = N / 2;
rep(c, 1, M + 1) {
int cost = min(sz0 - mx[0][c], sz1 - mx[1][c]);
print(cost);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tst = 1;
// cin >> tst;
while (tst--) {
solve();
}
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... |