이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int inf = 1e9;
// first
// memory optimization
// second
// 0 - all 0,
// 1 - all 1
// 2 - no changes,
// thrid
// 0 not have xor
// 1 have xor
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, cr = 1, pr = 0;
string a, b;
cin >> n >> a >> b;
vector < vector < vector < int > > > dp(2, vector < vector < int > > (3, vector < int > (2, inf)));
dp[pr][2][0] = 0;
for(int i = 0; i < n; ++ i) {
dp[cr] = {{inf, inf}, {inf, inf}, {inf, inf}};
if(a[i] == b[i]) {
dp[cr][2][0] = min({dp[pr][2][0], dp[pr][2][1], dp[pr][1][0], dp[pr][1][1], dp[pr][0][0], dp[pr][0][1]});
} else {
dp[cr][2][1] = min({dp[pr][2][0] + 1, dp[pr][2][1], dp[pr][1][0] + 1, dp[pr][1][1], dp[pr][0][0] + 1, dp[pr][0][1]});
}
if(b[i] == '0') {
dp[cr][0][0] = min({dp[pr][0][0], dp[pr][2][0] + 1, dp[pr][2][1] + 1,
dp[pr][0][1], dp[pr][1][0] + 1, dp[pr][1][1] + 1});
dp[cr][1][1] = min({dp[pr][1][1], dp[pr][1][0] + 1, dp[pr][2][1] + 1,
dp[pr][0][1] + 1, dp[pr][2][0] + 2, dp[pr][0][0] + 2});
} else {
dp[cr][1][0] = min({dp[pr][1][0], dp[pr][2][0] + 1, dp[pr][2][1] + 1,
dp[pr][1][1], dp[pr][0][0] + 1, dp[pr][0][1] + 1});
dp[cr][0][1] = min({dp[pr][0][1], dp[pr][0][0] + 1, dp[pr][2][1] + 1,
dp[pr][1][1] + 1, dp[pr][2][0] + 2, dp[pr][1][0] + 2});
}
swap(cr, pr);
}
cout << min({dp[pr][0][0], dp[pr][0][1], dp[pr][1][0], dp[pr][1][1], dp[pr][2][0], dp[pr][2][1]});
}
컴파일 시 표준 에러 (stderr) 메시지
lamp.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
24 | main() {
| ^~~~| # | 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... |