이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |