답안 #879423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879423 2023-11-27T10:43:49 Z vjudge1 Lamps (JOI19_lamps) C++17
100 / 100
213 ms 153340 KB
// https://oj.uz/problem/view/JOI19_lamps

#include <bits/stdc++.h>
using namespace std;

enum {
        Z = 0,
        O = 1,
        ZO = 2,
        OZ = 3,
        N = 4,
        ON = 1,
        OFF = 0
};

int32_t main() {
        ios_base::sync_with_stdio(0);
        cin.tie(0);

        int n;
        string a, b;
        cin >> n >> a >> b;
        const int inf = 1e9 + 7;
        vector<vector<vector<int>>> f(n + 1, vector<vector<int>>(2, vector<int>(5, inf)));
        f[0][0][N] = 0;

        // flip last

        for (int i = 0; i < n; i++) {
                for (int j = 0; j < 2; j++) {
                        for (int jj = 0; jj < 5; jj++) {
                                if (f[i][j][jj] == inf) continue;
                        }
                        for (int jj = 0; jj < 2; jj++) {
                                if ((0 ^ jj) == b[i] - '0') {
                                        f[i + 1][jj][Z] = min({f[i + 1][jj][Z],
                                                               f[i][j][Z],
                                                               f[i][j][OZ],
                                                               f[i][j][N] + 1,
                                                               f[i][j][O] + 1,
                                                               f[i][j][ZO]}) +
                                                          (j < jj);
                                        f[i + 1][jj][ZO] = min({f[i + 1][jj][ZO],
                                                                f[i][j][Z] + 1,
                                                                f[i][j][OZ] + 1,
                                                                f[i][j][N] + 2,
                                                                f[i][j][O] + 1,
                                                                f[i][j][ZO]}) +
                                                           (j < jj);
                                }
                                if ((1 ^ jj) == b[i] - '0') {
                                        f[i + 1][jj][O] = min({f[i + 1][jj][O],
                                                               f[i][j][Z] + 1,
                                                               f[i][j][OZ],
                                                               f[i][j][N] + 1,
                                                               f[i][j][O],
                                                               f[i][j][ZO]}) +
                                                          (j < jj);
                                        f[i + 1][jj][OZ] = min({f[i + 1][jj][OZ],
                                                                f[i][j][Z] + 1,
                                                                f[i][j][OZ],
                                                                f[i][j][N] + 2,
                                                                f[i][j][O] + 1,
                                                                f[i][j][ZO] + 1}) +
                                                           (j < jj);
                                }
                                if ((a[i] ^ jj) == b[i]) {
                                        f[i + 1][jj][N] = min({f[i + 1][jj][N],
                                                               f[i][j][N],
                                                               f[i][j][O],
                                                               f[i][j][Z],
                                                               f[i][j][OZ],
                                                               f[i][j][ZO]}) +
                                                          (j < jj);
                                }
                        }
                }
        }

        int res = inf;
        for (int i = 0; i < 2; i++) {
                for (int j = 0; j < 5; j++) {
                        res = min(res, f[n][i][j]);
                }
        }
        cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 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 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 588 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 348 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 348 KB Output is correct
28 Correct 0 ms 360 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 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 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 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 588 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 348 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 348 KB Output is correct
28 Correct 0 ms 360 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 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 716 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 708 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 372 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 173 ms 152992 KB Output is correct
8 Correct 194 ms 153096 KB Output is correct
9 Correct 170 ms 153000 KB Output is correct
10 Correct 169 ms 153080 KB Output is correct
11 Correct 170 ms 152984 KB Output is correct
12 Correct 168 ms 152992 KB Output is correct
13 Correct 180 ms 152952 KB Output is correct
14 Correct 169 ms 153100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 1 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 1 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 588 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 348 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 348 KB Output is correct
28 Correct 0 ms 360 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 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 344 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 1 ms 604 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 716 KB Output is correct
46 Correct 1 ms 604 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 604 KB Output is correct
52 Correct 1 ms 708 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 764 KB Output is correct
59 Correct 0 ms 348 KB Output is correct
60 Correct 0 ms 372 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 173 ms 152992 KB Output is correct
66 Correct 194 ms 153096 KB Output is correct
67 Correct 170 ms 153000 KB Output is correct
68 Correct 169 ms 153080 KB Output is correct
69 Correct 170 ms 152984 KB Output is correct
70 Correct 168 ms 152992 KB Output is correct
71 Correct 180 ms 152952 KB Output is correct
72 Correct 169 ms 153100 KB Output is correct
73 Correct 173 ms 153100 KB Output is correct
74 Correct 170 ms 153248 KB Output is correct
75 Correct 170 ms 152936 KB Output is correct
76 Correct 173 ms 152992 KB Output is correct
77 Correct 188 ms 152872 KB Output is correct
78 Correct 170 ms 153096 KB Output is correct
79 Correct 176 ms 153092 KB Output is correct
80 Correct 175 ms 153064 KB Output is correct
81 Correct 191 ms 153096 KB Output is correct
82 Correct 173 ms 153044 KB Output is correct
83 Correct 178 ms 152984 KB Output is correct
84 Correct 183 ms 153100 KB Output is correct
85 Correct 181 ms 153160 KB Output is correct
86 Correct 174 ms 152916 KB Output is correct
87 Correct 176 ms 152928 KB Output is correct
88 Correct 205 ms 152992 KB Output is correct
89 Correct 172 ms 153340 KB Output is correct
90 Correct 213 ms 152916 KB Output is correct
91 Correct 181 ms 152988 KB Output is correct
92 Correct 177 ms 153092 KB Output is correct
93 Correct 178 ms 153096 KB Output is correct
94 Correct 186 ms 153276 KB Output is correct
95 Correct 179 ms 153100 KB Output is correct
96 Correct 180 ms 153008 KB Output is correct
97 Correct 192 ms 153212 KB Output is correct
98 Correct 179 ms 153096 KB Output is correct
99 Correct 180 ms 152904 KB Output is correct
100 Correct 185 ms 153104 KB Output is correct
101 Correct 191 ms 153100 KB Output is correct
102 Correct 213 ms 152988 KB Output is correct