#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 = 1e6+1,MOD = 1e9+7;
#define chmin(a,b) a = min(a,b);
const int BUF_SZ=1<<20;
char buf[BUF_SZ];
int pos;
int len;
inline char gc() {
if (pos == len) {
pos = 0;
len = (int)fread(buf, 1, BUF_SZ, stdin);
}
while(buf[pos]<'0'||'9'<buf[pos])pos++;
return buf[pos++];
}
inline char next_char() {
if (pos == len) {
pos = 0;
len = (int)fread(buf, 1, BUF_SZ, stdin);
}
return buf[pos++];
}
inline int read_int() {
int x;
char ch=next_char();
while(ch<'0'||'9'<ch)ch=next_char();
x = ch - '0';
while (isdigit(ch = next_char())) { x = x * 10 + (ch - '0'); }
return x;
}
const int BB=20;
char out[BB];
int curind=0;
inline void flush(){
fwrite(out,1,curind,stdout);
curind=0;
}
inline void putchar(char c){
out[curind++]=c;
if(curind==BB)flush();
}
char temp[10];
inline void putuint(int i){
int lll=0;
while(i){
temp[lll++]=(i%10)+'0';
i/=10;
}
while(lll){
putchar(temp[--lll]);
}
}
char a[N],b[N];
inline int now(const int& p,const int& t) {
if (t < 2) return t;
if (!p) return (t == 1);
return (int)a[p-1];
};
void solve() {
int n;
n = read_int();
for (int i = 0;i<n;i++) a[i] = gc();
for (int i = 0;i<n;i++) b[i] = gc();
for (auto& it : a) it-='0';
for (auto& it : b) it-='0';
int dp[3],dp2[3];
dp[0] = dp[1] = dp[2] = dp2[0] = dp2[1] = inf;
dp2[2] = 0;
for (int i = 0;i<n;i++) {
for (int j = 0;j<=2;j++) {
if (dp2[j] == inf) continue;
int swi = (i && (now(i,j) != b[i-1]));
if (!swi) {
for (int jj = 0;jj<3;jj++) chmin(dp[jj],dp2[j]+(jj<2 && j!=jj)+(now(i+1,jj)!=b[i]));
}
else {
for (int jj = 0;jj<3;jj++) chmin(dp[jj],dp2[j]+(jj<2 && j!=jj));
}
}
for (int j = 0;j<3;j++) {
dp2[j] = dp[j];
dp[j] = inf;
}
}
int ans = inf;
for (int j = 0;j<3;j++) ans = min(ans,dp2[j]);
putuint(ans);
flush();
}
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... |