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;
typedef long long ll;
const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;
#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define mp make_pair
#define pb push_back
bool mini(auto &x, const auto &y) {
if (y < x) {
x = y;
return 1;
}
return 0;
}
bool maxi(auto &x, const auto &y) {
if (y > x) {
x = y;
return 1;
}
return 0;
}
void run();
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
run();
return 0;
}
const int N = 20;
const int M = 20;
int n, m;
int a[N];
bool test(int mask, int bit) {
return mask & (1 << bit);
}
bool ok(vector<int> &x) {
rep(i, 1, sz(x)) {
if ((x[i] - x[i - 1]) % 2 == 0) {
return 0;
}
}
return 1;
}
void run() {
cin >> n >> m;
rep(i, 0, n) {
cin >> a[i];
a[i]--;
}
rep(c, 0, m) {
int ans = INF;
rep(mask, 1, (1 << n) - 1) {
vector<int> x, y;
rep(bit, 0, n) {
if (test(mask, bit)) {
x.pb(bit);
} else {
y.pb(bit);
}
}
if (!ok(x) || !ok(y)) {
continue;
}
int cnt_c = 0;
for (int p : x) {
if (a[p] == c) {
cnt_c++;
}
}
if (!cnt_c) {
continue;
}
vector<int> wow(m);
for (int p : y) {
wow[a[p]]++;
}
int kek = *max_element(all(wow));
mini(ans, sz(x) - cnt_c + sz(y) - kek);
}
cout << ans << "\n";
}
}
# | 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... |