This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int dp[2][2][3],n;
string A,B;
char conv(char a,int t,int s){
if(!s)a='0';
if(s==1)a='1';
if(t)a=(char)(1-(int)(a-'0')+'0');
return a;
}
int32_t main(){
boost;
//freopen(".in","r",stdin);
cin>>n>>A>>B;
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 2; ++j)
for (int z = 0; z < 3; ++z)
dp[i][j][z]=INF;
dp[0][0][2]=0;
for (int idx = 0; idx < n; ++idx)
{
for (int t = 0; t < 2; ++t)
for (int s = 0; s < 3; ++s)
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 3; ++j)
{
int cost=0;
cost+=(i?(i!=t):0)+((j!=2)?(j!=s):0);
if(conv(A[idx],i,j)!=B[idx])continue;
dp[(idx+1)&1][i][j]=min(dp[(idx+1)&1][i][j],dp[idx&1][t][s]+cost);
}
for (int j = 0; j < 2; ++j)
for (int z = 0; z < 3; ++z)
dp[idx&1][j][z]=INF;
}
int ans=INF;
for (int i = 0; i < 2; ++i)
for (int j = 0; j < 3; ++j)ans=min(ans,dp[n&1][i][j]);
cout<<ans;
return 0;
}
//long long
//array bounds
//special cases
//binary search
# | 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... |