Submission #937667

#TimeUsernameProblemLanguageResultExecution timeMemory
937667groshiLamps (JOI19_lamps)C++17
4 / 100
24 ms33672 KiB
#include<bits/stdc++.h> using namespace std; //#define int long long int dp[1000100][8]; int inf=1e9; int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin>>n; string a,b; cin>>a>>b; a='$'+a; b='$'+b; for(int i=0;i<=n;i++) for(int j=0;j<6;j++) dp[i][j]=inf; dp[0][0]=0; for(int i=1;i<=n;i++) { if(b[i]=='0') dp[i][5]=min({dp[i-1][0]+2,dp[i-1][1]+1,dp[i-1][4]+1,dp[i-1][5]}); if(b[i]=='1') dp[i][4]=min(dp[i-1][0]+1,dp[i-1][4]); dp[i][4]=min(dp[i][4],dp[i][5]); if(b[i]=='1') dp[i][3]=min({dp[i-1][0]+2,dp[i-1][1]+1,dp[i-1][3]+1,dp[i-1][3]}); if(b[i]=='0') dp[i][2]=min(dp[i-1][0]+1,dp[i-1][2]); dp[i][2]=min({dp[i][2],dp[i][3]}); if(a[i]!=b[i]) dp[i][1]=min(dp[i-1][1],dp[i-1][0]+1); dp[i][1]=min({dp[i][1],dp[i][3],dp[i][5]}); if(a[i]==b[i]) dp[i][0]=dp[i-1][0]; dp[i][0]=min({dp[i][0],dp[i][1],dp[i][2],dp[i][3],dp[i][4],dp[i][5]}); //cout<<i<<": "<<dp[i][0]<<" "<<dp[i][1]<<" "<<dp[i][2]<<" "<<dp[i][3]<<" "<<dp[i][4]<<" "<<dp[i][5]<<"\n"; } cout<<dp[n][0]; 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...