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;
string A, B;
int dp[1000001][3];
char apply(char a, int y) {
return (y == 0) ? '0' : (y == 1) ? '1' : a;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n; cin >> n;
cin >> A >> B;
memset(dp, 0x3f3f3f3f, sizeof(dp));
dp[0][2] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
int cot = dp[i][j];
if (j != k && k != 2) cot++;
if ((i == 0 || apply(A[i - 1], j) == B[i - 1]) &&
apply(A[i], k) != B[i])
++cot;
dp[i+1][k] = min(dp[i+1][k], cot);
}
}
}
cout << min({ dp[n][0], dp[n][1], dp[n][2] });
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... |