Submission #596774

#TimeUsernameProblemLanguageResultExecution timeMemory
596774penguinhackerLamps (JOI19_lamps)C++17
100 / 100
48 ms14212 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define ar array const int mxN=1e6; int n, dp[mxN][3]; // use 0, use 1, use nothing string a, b; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> a >> b; memset(dp, 0x3f, sizeof(dp)); dp[0][0]=(a[0]!=b[0]); dp[0][1]=1+(b[0]=='1'); dp[0][2]=1+(b[0]=='0'); for (int i=1; i<n; ++i) { for (int j=0; j<3; ++j) { for (int k=0; k<3; ++k) { int dif1=j==1?b[i-1]=='1':j==2?b[i-1]=='0':b[i-1]!=a[i-1]; int dif2=k==1?b[i]=='1':k==2?b[i]=='0':b[i]!=a[i]; dp[i][k]=min(dp[i][k], dp[i-1][j]+(k>0&&j!=k)+(dif2&&!dif1)); } } } cout << min({dp[n-1][0], dp[n-1][1], dp[n-1][2]}); 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...