#include <bits/stdc++.h>
#define ar array
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
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 <int> dp(n + 1, 1e9);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
vector <int> cnt(3, 1);
int now = 2, eq = 0, tog = 1;
for (int j = i; j >= 1; j--) {
if (b[j] != now)
cnt[b[j]]++;
now = b[j];
if (a[j] == b[j]) {
tog = 1e9;
} else {
eq = 1e9;
}
dp[i] = min(dp[i], dp[j - 1] + min(min(cnt[0], cnt[1]), min(eq, tog)));
}
}
cout << dp[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... |