This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
using ii = pair<int, int>;
int n, m;
vector<int> c, cnt;
vector< vector<int> > vec[2];
set<ii> rem;
void upd (int col, int val) {
rem.erase( { cnt[col], col } );
cnt[col] += val;
rem.insert( { cnt[col], col } );
}
int solve (int col, bool _) {
int cnt_rem = n - cnt[col];
for (int _col : vec[_][col]) upd (_col, -1), --cnt_rem;
rem.erase( { cnt[col], col } );
if (rem.size() ) cnt_rem -= (*rem.rbegin() ).fi;
rem.insert( { cnt[col], col } );
for (int _col : vec[_][col]) upd (_col, 1);
return cnt_rem + (int)vec[_][col].size();
}
int main () {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
cnt.assign(m, 0);
c.assign(n, 0);
for (int i = 0; i < n; ++i) cin >> c[i], --c[i], ++cnt[ c[i] ];
for (int _ = 0; _ < 2; ++_) {
vec[_].assign(m, vector<int>() );
for (int i = _; i + 1 < n; i += 2) {
if (c[i] != c[i + 1]) {
vec[_][ c[i] ].pb(c[i + 1]);
vec[_][ c[i + 1] ].pb(c[i]);
}
}
}
for (int col = 0; col < m; ++col) rem.insert( { cnt[col], col } );
for (int col = 0; col < m; ++col) cout << min(solve(col, 0), solve(col, 1) ) << '\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... |