이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 100002, M = 10;
int a[N], ans[M];
int pref[N], suf[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
memset(ans, 0x3f, sizeof(ans));
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
--a[i];
}
for (int c1 = 0; c1 < m; ++c1) {
for (int c2 = 0; c2 < m; ++c2) {
int c[2] = {c1, c2};
pref[1] = min(c[0] != a[1], c[1] != a[1]);
for (int i = 2; i <= n; ++i) {
pref[i] = min((c[0] != a[i - 1]) + (c[0] != a[i]), (c[1] != a[i - 1]) + (c[1] != a[i])) + pref[i - 2];
}
suf[n] = min(c[0] != a[n], c[1] != a[n]);
for (int i = n - 1; i > 0; --i) {
suf[i] = min((c[0] != a[i + 1]) + (c[0] != a[i]), (c[1] != a[i + 1]) + (c[1] != a[i])) + suf[i + 2];
}
for (int i = 1; i <= n - 1; ++i) {
int now = (i > 1 ? a[i - 1] != c[0] : 0) + pref[i - 2] + (i + 2 <= n ? a[i + 2] != c[1] : 0) + suf[i + 3] +
(a[i] != c[0]) + (a[i + 1] != c[1]);
ans[c1] = min(ans[c1], now);
ans[c2] = min(ans[c2], now);
}
}
}
for (int i = 0; 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... |