이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int n, sol = 1e9;
string a, b;
int dp[MAXN][3][2];
char f (char c, int tip, int toggle) {
if (tip == 0) c = '0'; else if (tip == 1) c = '1';
if (toggle) {
if (c == '0') c = '1'; else c = '0';
}
return c;
}
int calc (int pos, int tip, int toggle) {
if (pos == n) return 0;
if (dp[pos][tip][toggle] != -1) return dp[pos][tip][toggle];
int res = 1e9;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
int cost = 0;
if (i <= 1 && tip != i) cost++;
if (j == 1 && toggle == 0) cost++;
if (b[pos] == f(a[pos], i, j)) res = min(res, cost + calc(pos + 1, i, j));
}
}
return dp[pos][tip][toggle] = res;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> a >> b;
memset(dp, -1, sizeof dp);
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 2; j++) {
int cost = 0;
if (i <= 1) cost++;
if (j == 1) cost++;
sol = min(sol, cost + calc(0, i, j));
}
}
cout << sol;
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... |