This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Code by Parsa Eslami
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORR(i,a,b) for(int i=a;i>=b;i--)
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define all(x) x.begin(),x.end()
#define SZ(x) ((int)x.size())
#define bit(i,j) ((j>>i)&1)
#define pb push_back
#define lc 2*id
#define rc 2*id+1
#define dmid int mid=(r+l)/2
#define err(x) cerr<#x<<" : "<<x<<'\n'
using namespace std;
int get(){
int x; cin>>x; return x;
}
int32_t main(){
iostream::sync_with_stdio(0); cin.tie(0);
int n=get();
bool a[n+1]={}; bool b[n+1];
string s; cin>>s; FOR(i,0,n-1) a[i+1]=s[i]-'0';
cin>>s; FOR(i,0,n-1) b[i+1]=s[i]-'0';
int val[2][3][2];
FOR(B,0,1) FOR(i,0,2) FOR(j,0,1){
if(i==2) val[B][i][j]=B^j;
else val[B][i][j]=i^j;
}
int dis[3][2][3][2];
FOR(i0,0,2) FOR(j0,0,1) FOR(i1,0,2) FOR(j1,0,1){
dis[i0][j0][i1][j1]=0;
if(j1==1&&j0==0) dis[i0][j0][i1][j1]++;
if(i1!=2) dis[i0][j0][i1][j1]+=(i0!=i1);
}
int dp[n+1][3][2];
FOR(w,0,n) FOR(i,0,2) FOR(j,0,1) dp[w][i][j]=1e9;
dp[0][2][0]=0;
FOR(w,1,n) FOR(i,0,2) FOR(j,0,1){
if(val[a[w]][i][j]!=b[w]) continue;
FOR(i0,0,2) FOR(j0,0,1) minm(dp[w][i][j],dp[w-1][i0][j0]+dis[i0][j0][i][j]);
}
FOR(i,0,2) FOR(j,0,1) minm(dp[n][0][0],dp[n][i][j]);
cout<<dp[n][0][0]<<'\n';
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... |