This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define nl "\n"
#define all(v) v.begin(),v.end()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
int main() {
fast
ll n;
cin>>n;
string a,b;
cin>>a>>b;
ll dp[n+10][3][2];
memset(dp,0x3f, sizeof(dp));
dp[n][0][0]=0;
for(ll i=n-1;i>=0;i--){
for(ll j=0;j<3;j++){
for(ll k=0;k<2;k++){
ll val=a[i]-'0';
if(j==1)val=0;
if(j==2)val=1;
if(k==1)val^=1;
if(val!=(b[i]-'0'))continue;
for(ll j2=0;j2<3;j2++){
for(ll k2=0;k2<2;k2++){
dp[i][j][k]=min(dp[i][j][k],dp[i+1][j2][k2]+(j>0&&j!=j2)+(k>0&&k2!=k));
}
}
}
}
}
ll ans=1e18;
for(ll j=0;j<3;j++)
for(ll k=0;k<2;k++)ans=min(ans,dp[0][j][k]);
cout<<ans;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |