This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)
const int MN = 1000005;
int n, dp[MN][3][2];
char a[MN], b[MN];
int32_t main() {
boost();
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
memset(dp, 0x3f, sizeof(dp));
dp[0][2][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 2; k++) {
for (int pj = 0; pj < 3; pj++) {
for (int pk = 0; pk < 2; pk++) {
int cur = j == 2 ? a[i] - '0' : j, tgt = (b[i] - '0') ^ k;
if (cur != tgt) continue;
int cost = 0;
if (j < 2 && j != pj) cost++;
if (k && !pk) cost++;
dp[i][j][k] = min(dp[i][j][k], dp[i - 1][pj][pk] + cost);
}
}
}
}
}
int ans = 0x3f3f3f3f;
for (int j = 0; j < 3; j++) for (int k = 0; k < 2; k++) ans = min(ans, dp[n][j][k]);
printf("%lld\n", ans);
return 0;
}
# | 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... |