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;
const int mxn = 1e6+5;
int n, m;
int a[mxn];
int main(int argc, char const *argv[]) {
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 1; i <= m; i++) {
// skip first
int best = n, curr = 0, mx, j;
map<int, int> cnt;
if(a[0] != i) curr++, cnt[a[0]]++;
for(j = 1; j < n-1; j += 2) {
if(a[j] != i && a[j+1] != i) {
cnt[a[j]]++, cnt[a[j+1]]++;
curr += 2;
}
else if(a[j] != i || a[j+1] != i) {
curr++;
}
}
if(j == n-1) if(a[n-1] != i) curr++, cnt[a[n-1]]++;
mx = 0;
for(auto p : cnt) mx = max(mx, p.second);
curr -= mx;
best = min(best, curr);
// pair first
curr = 0;
cnt.clear();
for(j = 0; j < n-1; j += 2) {
if(a[j] != i && a[j+1] != i) {
cnt[a[j]]++, cnt[a[j+1]]++;
curr += 2;
}
else if(a[j] != i || a[j+1] != i) {
curr++;
}
}
if(j == n-1) if(a[n-1] != i) curr++, cnt[a[n-1]]++;
mx = 0;
for(auto p : cnt) mx = max(mx, p.second);
curr -= mx;
best = min(best, curr);
cout << best << "\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... |