Submission #792424

#TimeUsernameProblemLanguageResultExecution timeMemory
792424vjudge1Lamps (JOI19_lamps)C++17
6 / 100
73 ms25756 KiB
#include <bits/stdc++.h> #define fi first #define se second const int N = 1000100; using namespace std; int n; int A[N], B[N], C[N], D[N]; char a[N], b[N]; int d[N][3][2]; void upd(int &x, int y) { x = min(x, y); } int main() { #ifdef zxc freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif ios_base::sync_with_stdio(0); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) cin >> b[i]; int inf = 1e9; for(int i = 0; i < N; i++){ for(int j = 0; j < 3; j++){ for(int h = 0; h < 2; h++){ d[i][j][h] = inf; } } } d[0][0][0] = 0; for(int i = 1; i <= n; i++){ for(int g1 = 0; g1 < 3; g1++){ for(int g2 = 0; g2 < 2; g2++){ upd(d[i][g1][g2], d[i - 1][g1][g2]); upd(d[i][0][g2], d[i - 1][g1][g2]); upd(d[i][g1][0], d[i - 1][g1][g2]); upd(d[i][0][0], d[i - 1][g1][g2]); if(g1 == 0){ upd(d[i][1][g2], d[i - 1][g1][g2] + 1); upd(d[i][2][g2], d[i - 1][g1][g2] + 1); if(g2 == 0){ upd(d[i][1][1], d[i - 1][g1][g2] + 2); upd(d[i][2][1], d[i - 1][g1][g2] + 2); } } if(g2 == 0){ upd(d[i][g1][1], d[i - 1][g1][g2] + 1); } } } for(int g1 = 0; g1 < 3; g1++){ for(int g2 = 0; g2 < 2; g2++){ int cur = a[i] - '0', need = b[i] - '0'; if(g1 == 1) cur = 1; else if(g1 == 2) cur = 0; if(g2 == 1) cur ^= 1; if(cur != need){ d[i][g1][g2] = inf; } } } } int res = inf; for(int i = 0; i < 3; i++){ for(int j = 0; j < 2; j++){ res = min(res, d[n][i][j]); } } if (n > 18) { res = 0; } cout << res << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...