Submission #493170

#TimeUsernameProblemLanguageResultExecution timeMemory
493170LukapLamps (JOI19_lamps)C++14
4 / 100
396 ms41488 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e6 + 7; const int INF = 1e9 + 7; int n; int a[MAXN], b[MAXN]; int dp[MAXN][4][2]; int dodaj (int i, int x, int y, int fx, int fy) { if (a[i] == b[i]) { if (x == 3 && fx == 0) return INF; if (x >= 1 && x <= 2 && x % 2 != b[i] && fx == 0) return INF; if (x == 0 && fx == 1) return INF; if (x >= 1 && x <= 2 && x % 2 == b[i] && fx == 1) return INF; } else { if (x >= 1 && x <= 2 && x % 2 != b[i] && fx == 0) return INF; if (x == 0 && fx == 0) return INF; if (x >= 1 && x <= 2 && x % 2 == b[i] && fx == 1) return INF; } if (fx == 0) { if (x == 3) return INF; else if (x != 0 && x != y) return 1; else return 0; } else { if (fy == 0) { if (x != 3) return INF; return 1; } else { if (x == 3) return 1; else if (x != 0 && x != y) return 1; else return 0; } } } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; for (int i = 0; i < n + 1; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 2; k++) dp[i][j][k] = INF; } } for (int i = 0; i < n; i++) { char c; cin >> c; a[i + 1] = c - '0'; } for (int i = 0; i < n; i++) { char c; cin >> c; b[i + 1] = c - '0'; } dp[0][0][0] = 0; for (int i = 1; i < n + 1; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 2; k++) { for (int l = 0; l < 4; l++) { for (int m = 0; m < 2; m++) dp[i][j][k] = min (dp[i][j][k], dp[i - 1][l][m] + dodaj (i, j, l, k, m)); } // cout << i << ' ' << j << ' ' << k << ' ' << dp[i][j][k] << "\n"; } } } int rj = INF; for (int i = 0; i < 4; i++) { for (int j = 0; j < 2; j++) rj = min (rj, dp[n][i][j]); } cout << rj; 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...