#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int inf = 2e9,N = 4e5+1,MOD = 1e9+7;
void solve() {
int n;
cin >> n;
string a,b;
cin >> a >> b;
for (auto& it : a) it-='0';
for (auto& it : b) it-='0';
int dp[n+1][3];
for (int i = 0;i<=n;i++) for (int j = 0;j<3;j++) dp[i][j] = inf;
dp[0][2] = 0;
auto now = [&](int p,int t) {
if (!p) return (int)(t==1);
if (t == 1) return 1;
if (t == 0) return 0;
return (int)a[p-1];
};
for (int i = 0;i<n;i++) {
for (int j = 0;j<=2;j++) {
if (dp[i][j] == inf) continue;
int swi = (i && (now(i,j) != b[i-1]));
for (int jj = 0;jj<2;jj++) {
dp[i+1][jj] = min(dp[i+1][jj],dp[i][j]+(j!=jj)+(now(i+1,jj)!=b[i] && !swi));
}
dp[i+1][2] = min(dp[i+1][2],dp[i][j]+(now(i+1,2)!=b[i] && !swi));
}
}
int ans = inf;
for (int j = 0;j<3;j++) ans = min(ans,dp[n][j]);
cout << ans << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | 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... |