Submission #823418

#TimeUsernameProblemLanguageResultExecution timeMemory
823418yanndevLamps (JOI19_lamps)C++17
100 / 100
221 ms64972 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int INF = 1e9; const int MX = (int)1e6 + 42; int dp[MX][3][2]; void solve(int tcId) { int n; cin >> n; vector<int> a (n + 1, 0); vector<int> b (n + 1, 0); for (int i = 1; i <= n; i++) { char v; cin >> v; a[i] = v - '0'; } for (int i = 1; i <= n; i++) { char v; cin >> v; b[i] = v - '0'; } for (int i = 0; i <= n; i++) for (int j = 0; j < 3; j++) for (int k = 0; k < 2; k++) dp[i][j][k] = INF; dp[0][2][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < 2; k++) { for (int pJ = 0; pJ < 3; pJ++) { for (int pk = 0; pk < 2; pk++) { int cnt = 0; if (pJ != j && j != 2) cnt++; if (k != pk && k != 0) cnt++; int v = a[i]; if (j == 0) v = 0; else if (j == 1) v = 1; if (k) v ^= 1; if (v == b[i]) dp[i][j][k] = min(dp[i][j][k], dp[i - 1][pJ][pk] + cnt); } } } } } int ans = 1e18; for (int i = 0; i < 3; i++) for (int j = 0; j < 2; j++) ans = min(ans, dp[n][i][j]); cout << ans << '\n'; } signed main() { bool multi = false; if (!multi) { solve(42); } else { int t; cin >> t; while (t--) solve(t); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...