Submission #422378

#TimeUsernameProblemLanguageResultExecution timeMemory
422378qwerasdfzxclLamps (JOI19_lamps)C++14
4 / 100
27 ms20032 KiB
#include <bits/stdc++.h> typedef long long ll; using namespace std; string x, y; int dp[1001000][3], ans[1001000]; int main(){ cin.tie(NULL); ios_base::sync_with_stdio(false); int n; cin >> n >> x >> y; if (x[0]==y[0]){ if (y[0]=='0') dp[0][0] = 1, dp[0][1] = 2; else dp[0][0] = 2, dp[0][1] = 1; dp[0][2] = 2; } else{ if (y[0]=='0') dp[0][0] = 1, dp[0][1] = 2; else dp[0][0] = 2, dp[0][1] = 1; dp[0][2] = 1; ans[0] = 1; } for (int i=1;i<n;i++){ if (y[i]==y[i-1]) dp[i][0] = dp[i-1][0], dp[i][1] = dp[i-1][1]; else dp[i][y[i]-'0'] = dp[i-1][y[i]-'0'], dp[i][(y[i]-'0')^1] = dp[i-1][(y[i]-'0')^1]+1; if (x[i]!=y[i]){ dp[i][2] = min(dp[i-1][2], ans[i-1]+1); ans[i] = min(ans[i-1]+1, min(dp[i][0], min(dp[i][1], dp[i][2]))); } else{ dp[i][2] = min(ans[i-1]+2, min(dp[i-1][2], dp[i-1][(y[i]-'0')^1])+1); ans[i] = ans[i-1]; } } /*for (int i=0;i<n;i++) printf("%d", dp[i][0]); printf("\n"); for (int i=0;i<n;i++) printf("%d", dp[i][1]); printf("\n"); for (int i=0;i<n;i++) printf("%d", dp[i][2]); printf("\n"); for (int i=0;i<n;i++) printf("%d", ans[i]); printf("\n");*/ cout << ans[n-1]; 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...