#include <bits/stdc++.h>
#define ar array
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
const int inf = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector <int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
char c; cin >> c;
a[i] = c - '0';
}
for (int i = 1; i <= n; i++) {
char c; cin >> c;
b[i] = c - '0';
}
vector <vector <int>> dp(n + 1, vector <int> (8, inf));
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int ma = 0; ma < 8; ma++) {
int cur = a[i];
if (ma & 1) cur = 0;
if (ma & 2) cur = 1;
if (ma & 4) cur ^= 1;
if (cur != b[i]) continue;
for (int mb = 0; mb < 8; mb++) {
int op = 0;
for (int j = 0; j < 3; j++)
op += ((ma >> j) & 1) > ((mb >> j) & 1);
dp[i][ma] = min(dp[i][ma], dp[i - 1][mb] + op);
}
}
}
int ans = inf;
for (int i = 0; i < 8; i++)
ans = min(ans, dp[n][i]);
cout << ans;
}
# | 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... |