Submission #1083136

# Submission time Handle Problem Language Result Execution time Memory
1083136 2024-09-02T16:13:20 Z Sharky Lamps (JOI19_lamps) C++17
100 / 100
275 ms 4388 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];
            if (dp[prev][x][y][z] >= inf) continue;
            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 && x < 3 && y == 3) {
                    ckmin(dp[cur][x][j][z], dp[prev][x][y][z] + 1);
                    ckmin(dp[cur][j][x][z], dp[prev][x][y][z] + 1);
                }
                else if (j != x && j != y && x < 3 && y < 3 && z == 3) {
                    ckmin(dp[cur][x][y][j], dp[prev][x][y][z] + 1);
                    ckmin(dp[cur][x][j][y], dp[prev][x][y][z] + 1);
                    ckmin(dp[cur][j][x][y], dp[prev][x][y][z] + 1);
                }
            }
            ckmin(dp[cur][3][3][3], dp[prev][x][y][z]);
            ckmin(dp[cur][x][3][3], dp[prev][x][y][z]);
            ckmin(dp[cur][y][3][3], dp[prev][x][y][z]);
            ckmin(dp[cur][z][3][3], dp[prev][x][y][z]);
            ckmin(dp[cur][x][y][3], dp[prev][x][y][z]);
            ckmin(dp[cur][x][z][3], dp[prev][x][y][z]);
            ckmin(dp[cur][y][z][3], dp[prev][x][y][z]);
            ckmin(dp[cur][x][y][z], dp[prev][x][y][z]);
        }
        for (auto& arr : st) {
            char o = a[i];
            for (int j = 0; j < 3; j++) {
                int cmd = arr[j];
                if (cmd == 3) continue;
                if (cmd == 0) o = '0';
                else if (cmd == 1) o = '1';
                else if (o == '1') o = '0';
                else o = '1';
            }
            if (o != b[i]) dp[cur][arr[0]][arr[1]][arr[2]] = inf;
            // cout << i << " " << arr[0] << " " << arr[1] << " " << arr[2] << " " << dp[cur][arr[0]][arr[1]][arr[2]] << '\n';
        }
    }
    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';
}

// 110010
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 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 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 464 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 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 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 464 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 464 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 476 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 428 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 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 263 ms 4352 KB Output is correct
8 Correct 193 ms 4388 KB Output is correct
9 Correct 213 ms 4176 KB Output is correct
10 Correct 199 ms 4184 KB Output is correct
11 Correct 198 ms 4188 KB Output is correct
12 Correct 226 ms 4272 KB Output is correct
13 Correct 232 ms 4320 KB Output is correct
14 Correct 218 ms 4348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 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 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 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 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 344 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 464 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 464 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 476 KB Output is correct
52 Correct 1 ms 348 KB Output is correct
53 Correct 1 ms 348 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 2 ms 348 KB Output is correct
57 Correct 1 ms 348 KB Output is correct
58 Correct 1 ms 428 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 344 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 263 ms 4352 KB Output is correct
66 Correct 193 ms 4388 KB Output is correct
67 Correct 213 ms 4176 KB Output is correct
68 Correct 199 ms 4184 KB Output is correct
69 Correct 198 ms 4188 KB Output is correct
70 Correct 226 ms 4272 KB Output is correct
71 Correct 232 ms 4320 KB Output is correct
72 Correct 218 ms 4348 KB Output is correct
73 Correct 230 ms 4184 KB Output is correct
74 Correct 219 ms 4176 KB Output is correct
75 Correct 204 ms 4176 KB Output is correct
76 Correct 217 ms 4344 KB Output is correct
77 Correct 221 ms 4188 KB Output is correct
78 Correct 206 ms 4184 KB Output is correct
79 Correct 192 ms 4188 KB Output is correct
80 Correct 246 ms 4344 KB Output is correct
81 Correct 218 ms 4304 KB Output is correct
82 Correct 201 ms 4188 KB Output is correct
83 Correct 226 ms 4348 KB Output is correct
84 Correct 236 ms 4184 KB Output is correct
85 Correct 275 ms 4348 KB Output is correct
86 Correct 229 ms 4344 KB Output is correct
87 Correct 228 ms 4180 KB Output is correct
88 Correct 227 ms 4188 KB Output is correct
89 Correct 235 ms 4348 KB Output is correct
90 Correct 243 ms 4284 KB Output is correct
91 Correct 229 ms 4352 KB Output is correct
92 Correct 230 ms 4188 KB Output is correct
93 Correct 238 ms 4368 KB Output is correct
94 Correct 234 ms 4280 KB Output is correct
95 Correct 253 ms 4184 KB Output is correct
96 Correct 234 ms 4184 KB Output is correct
97 Correct 236 ms 4184 KB Output is correct
98 Correct 241 ms 4184 KB Output is correct
99 Correct 245 ms 4348 KB Output is correct
100 Correct 242 ms 4180 KB Output is correct
101 Correct 237 ms 4348 KB Output is correct
102 Correct 236 ms 4180 KB Output is correct