This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/* * In the name of GOD */
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
#define F first
#define S second
#define mk make_pair
const int N = 1012345;
int dp[N][3][2];
int32_t main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int n, ans = N;
string a, b;
cin >> n >> a >> b;
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= 2; j++) {
for (int k = 0; k <= 1; k++) {
dp[i][j][k] = N;
if (i == 0) {
if (j == 2 && k == 0)
dp[i][j][k] = 0;
continue;
}
int x = (j == 2 ? a[i - 1] - '0' : j);
x ^= k;
if (x != b[i - 1] - '0') {
continue;
}
for (int j2 = 0; j2 <= 2; j2++) {
for (int k2 = 0; k2 <= 1; k2++) {
dp[i][j][k] = min(dp[i][j][k], dp[i - 1][j2][k2] + ((j != 2) && (j2 != j)) + ((k != 0) && (k != k2)));
}
}
if (i == n)
ans = min(ans, dp[i][j][k]);
}
}
}
cout << ans << '\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... |