# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1083053 |
2024-09-02T10:55:03 Z |
Sharky |
Lamps (JOI19_lamps) |
C++17 |
|
346 ms |
3676 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int inf = 1e9;
int n, dp[2][4][4][4];
char a[N], b[N];
void ckmin(int &x, int y) {
x = min(x, y);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
for (int l = 0; l < 4; l++) {
dp[i][j][k][l] = inf;
}
}
}
}
dp[0][3][3][3] = 0;
vector<array<int, 3>> st;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
if (i == 3 && j < 3) continue;
if (j == 3 && k < 3) continue;
if (i != 3 && j != 3 && i == j) continue;
if (i != 3 && k != 3 && i == k) continue;
if (j != 3 && k != 3 && j == k) continue;
st.push_back({i, j, k});
}
}
}
for (int i = 1; i <= n; i++) {
int cur = i&1, prev = 1 - cur;
for (auto& arr : st) {
int x = arr[0], y = arr[1], z = arr[2];
dp[cur][x][y][z] = inf;
}
for (auto& arr : st) {
int x = arr[0], y = arr[1], z = arr[2];
vector<bool> ok(4, 1);
if (b[i] == '1') ok[0] = 0;
if (b[i] == '0') ok[1] = 0;
if (a[i] == b[i]) ok[2] = 0;
if (a[i] != b[i]) ok[3] = 0;
for (int j = 0; j < 3; j++) {
if (!ok[j]) continue;
if (x == 3) ckmin(dp[cur][j][y][z], dp[prev][x][y][z] + 1);
else if (j != x && y == 3) ckmin(dp[cur][x][j][z], dp[prev][x][y][z] + 1);
else if (j != x && j != y && z == 3) ckmin(dp[cur][x][y][j], dp[prev][x][y][z] + 1);
}
if (x < 3 && y < 3 && z < 3 && ok[z]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
else if (x < 3 && y < 3 && z == 3 && ok[y]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
else if (x < 3 && y == 3 && z == 3 && ok[x]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
else if (x == 3 && y == 3 && z == 3 && ok[3]) ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
if (x < 3 && y < 3 && z < 3 && ok[y]) {
ckmin(dp[cur][x][y][3], dp[prev][x][y][z]);
} else if (x < 3 && y < 3 && z == 3 && ok[x]) {
ckmin(dp[cur][x][3][z], dp[prev][x][y][z]);
} else if (x < 3 && y == 3 && z == 3 && ok[3]) {
ckmin(dp[cur][3][y][z], dp[prev][x][y][z]);
}
}
}
int ans = inf;
for (auto& arr : st) {
int i = arr[0], j = arr[1], k = arr[2];
ans = min(ans, dp[n & 1][i][j][k]);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
472 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
472 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
600 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
346 ms |
3664 KB |
Output is correct |
8 |
Correct |
314 ms |
3676 KB |
Output is correct |
9 |
Correct |
344 ms |
3676 KB |
Output is correct |
10 |
Correct |
309 ms |
3524 KB |
Output is correct |
11 |
Correct |
321 ms |
3676 KB |
Output is correct |
12 |
Correct |
330 ms |
3668 KB |
Output is correct |
13 |
Correct |
318 ms |
3676 KB |
Output is correct |
14 |
Correct |
316 ms |
3676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
464 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
472 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
27 |
Halted |
0 ms |
0 KB |
- |