#include <bits/stdc++.h>
using namespace std;
signed main(){
int n; cin >> n;
string a, b; cin >> a >> b;
for ( int i = 0; i < n; i++ ){
a[i] -= '0', b[i] -= '0';
}
auto op = [&](int x, int j){
return j > 0 ? j - 1 : x;
};
vector <array<int,3>> dp(n);
for ( int i = 0; i < n; i++ ){
dp[i] = {n, n, n};
for ( auto p: {0, 1, 2} ){
for ( auto c: {0, 1, 2} ){
int cnt = 0;
if ( !i ) cnt = (c != 0);
else cnt = dp[i - 1][p] + (p != c && c != 0);
if ( (!i || op(a[i - 1], p) == b[i - 1]) && op(a[i], c) != b[i] ) cnt++;
dp[i][c] = min(dp[i][c], cnt);
}
}
}
cout << min({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << '\n';
}
# | 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... |