Submission #869613

#TimeUsernameProblemLanguageResultExecution timeMemory
86961312345678Lamps (JOI19_lamps)C++17
100 / 100
25 ms27824 KiB
#include <bits/stdc++.h> using namespace std; const int nx=1e6+5; int dp[nx][6], n; string a, b; int main() { cin.tie(NULL)->sync_with_stdio(false); cin>>n>>a>>b; dp[0][1]=dp[0][2]=dp[0][3]=dp[0][4]=dp[0][5]=1e9; for (int i=1; i<=n; i++) { dp[i][0]=dp[i][1]=dp[i][2]=dp[i][3]=dp[i][4]=dp[i][5]=1e9; int mn=min({dp[i-1][0], dp[i-1][1], dp[i-1][2], dp[i-1][3], dp[i-1][4], dp[i-1][5]}); if (a[i-1]==b[i-1]) dp[i][0]=mn; if (b[i-1]=='0') dp[i][1]=min({dp[i-1][1], mn+1, dp[i-1][5]}), dp[i][4]=min({dp[i-1][4], mn+2, dp[i-1][2]+1, dp[i-1][3]+1, dp[i-1][5]+1}); if (b[i-1]=='1') dp[i][2]=min({dp[i-1][2], mn+1, dp[i-1][4]}), dp[i][5]=min({dp[i-1][5], mn+2, dp[i-1][1]+1, dp[i-1][3]+1, dp[i-1][4]+1}); if (a[i-1]!=b[i-1]) dp[i][3]=min({dp[i-1][3], mn+1, dp[i-1][4], dp[i-1][5]}); } cout<<min({dp[n][0], dp[n][1], dp[n][2], dp[n][3], dp[n][4], dp[n][5]}); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...