Submission #598794

#TimeUsernameProblemLanguageResultExecution timeMemory
598794piOOERope (JOI17_rope)C++17
45 / 100
2578 ms1860 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...