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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
const int inf = 1e9 + 7;
int N; string A, B; cin >> N >> A >> B;
vector<array<int, 3>> dp(N + 1, {inf, inf, inf});
auto match = [&](int i, int j) {
char c = j == 2 ? A[i] : j + '0';
return c == B[i];
};
dp[0][2] = 0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j < 3; ++j) {
if (dp[i][j] != inf) {
for (int k = 0; k < 3; ++k) {
int c = dp[i][j];
c += j != k && k != 2;
c += i == 0 || (match(i - 1, j) && !match(i, k));
dp[i + 1][k] = min(dp[i + 1][k], c);
}
}
}
}
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... |