Submission #823420

#TimeUsernameProblemLanguageResultExecution timeMemory
823420yanndevLamps (JOI19_lamps)C++17
100 / 100
167 ms31700 KiB
#include <bits/stdc++.h> 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++) { if (dp[i - 1][pJ][pk] == INF) continue; 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 = 1e9; 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() { ios::sync_with_stdio(false); cin.tie(nullptr); solve(42); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...