# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
796806 |
2023-07-28T18:42:00 Z |
vjudge1 |
Lamps (JOI19_lamps) |
C++17 |
|
1 ms |
316 KB |
#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;
int dp[2][3][2];
// 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;
dp[pr][0][1] = dp[pr][1][1] = dp[pr][2][1] = dp[pr][0][0] = dp[pr][1][1] = dp[pr][2][0] = inf;
for(int i = 0; i < n; ++ i) {
dp[cr][0][0] = dp[cr][0][1] = dp[cr][2][0] =
dp[cr][1][0] = dp[cr][1][1] = dp[cr][2][1] = 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 << 1 + 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]});
}
Compilation message
lamp.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main() {
| ^~~~
lamp.cpp: In function 'int main()':
lamp.cpp:37:33: warning: operation on 'dp[pr][1][1]' may be undefined [-Wsequence-point]
37 | dp[pr][0][1] = dp[pr][1][1] = dp[pr][2][1] = dp[pr][0][0] = dp[pr][1][1] = dp[pr][2][0] = inf;
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |