// #pragma GCC optimize("O3")
// #pragma GCC optimization("Ofast,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i, l, r) for (int i = (l); i <= (r); i++)
#define FOD(i, r, l) for (int i = (r); i >= (l); i--)
#define fi first
#define se second
#define pii pair<int, int>
const ll mod = 1e9 + 7;
const int MAXN = 1e6 + 5;
const ll oo = 1e18 + 7;
const int base = 10;
int n;
int a[MAXN], b[MAXN];
int solve(){
int ans=0;
for(int i=1; i<=n; ){
int j=i;
if(a[i]==b[i]){
while(a[j]==b[j]){
j++;
}
i=j;
}
else{
ans++;
int j1=i;
while(b[j1]==b[i]){
j1++;
}
int j2=i;
while(a[j2]!=b[j2]){
j2++;
}
i=max(j1, j2);
}
}
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("test.txt", "r", stdin);
// freopen("o2.out", "w", stdout);
if(fopen(".inp", "r")){
freopen(".inp", "r", stdin);
freopen(".out", "w", stdout);
}
cin >> n;
FOR(i, 1, n){
char c;
cin >> c;
a[i]=(int)(c-'0');
}
FOR(i, 1, n){
char c;
cin >> c;
b[i]=(int)(c-'0');
}
int ans=oo;
ans=solve();
FOR(i, 1, n){
a[i]=1-a[i];
}
ans=min(ans, solve()+1);
cout << ans;
return 0;
}
Compilation message (stderr)
lamp.cpp: In function 'int main()':
lamp.cpp:59:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | freopen(".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
lamp.cpp:60:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
60 | freopen(".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~| # | 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... |