Submission #428848

# Submission time Handle Problem Language Result Execution time Memory
428848 2021-06-15T14:53:28 Z tengiz05 Lamps (JOI19_lamps) C++17
100 / 100
154 ms 33592 KB
#include <bits/stdc++.h>
constexpr int N = 1000000;
int dp[N + 1][2][2][2];
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int n;
    std::cin >> n;
    std::string a, b;
    std::cin >> a >> b;
    a = "#" + a;
    b = "#" + b;
    memset(dp, 0x3f, sizeof dp);
    dp[0][0][0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int a0 = 0; a0 < 2; a0++)
            for (int a1 = 0; a1 < 2; a1++)
                for (int xr = 0; xr < 2; xr++) {
                    char t = a[i];
                    if (a0) t = '0';
                    if (a1) t = '1';
                    if (xr) t ^= 1;
                    if (t != b[i]) {
                        continue;
                    }
                    int &ret = dp[i][a0][a1][xr];
                    ret = dp[i - 1][a0][a1][xr];
                    for (int A0 = 0; A0 < 2; A0++) {
                        for (int A1 = 0; A1 < 2; A1++) {
                            for (int XR = 0; XR < 2; XR++) {
                                ret = std::min(ret, dp[i - 1][A0][A1][XR] + (a0 > A0) + (a1 > A1) + (xr > XR));
                            }
                        }
                    }
                }
    }
    int ans = n;
    for (int a0 = 0; a0 < 2; a0++)
        for (int a1 = 0; a1 < 2; a1++)
            for (int xr = 0; xr < 2; xr++)
                ans = std::min(ans, dp[n][a0][a1][xr]);
    std::cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31544 KB Output is correct
2 Correct 14 ms 31572 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 14 ms 31564 KB Output is correct
5 Correct 19 ms 31592 KB Output is correct
6 Correct 16 ms 31564 KB Output is correct
7 Correct 14 ms 31540 KB Output is correct
8 Correct 15 ms 31564 KB Output is correct
9 Correct 14 ms 31564 KB Output is correct
10 Correct 14 ms 31576 KB Output is correct
11 Correct 14 ms 31580 KB Output is correct
12 Correct 15 ms 31532 KB Output is correct
13 Correct 14 ms 31532 KB Output is correct
14 Correct 19 ms 31592 KB Output is correct
15 Correct 14 ms 31564 KB Output is correct
16 Correct 15 ms 31560 KB Output is correct
17 Correct 14 ms 31516 KB Output is correct
18 Correct 21 ms 31564 KB Output is correct
19 Correct 14 ms 31624 KB Output is correct
20 Correct 14 ms 31564 KB Output is correct
21 Correct 17 ms 31564 KB Output is correct
22 Correct 15 ms 31564 KB Output is correct
23 Correct 14 ms 31564 KB Output is correct
24 Correct 15 ms 31568 KB Output is correct
25 Correct 15 ms 31548 KB Output is correct
26 Correct 15 ms 31564 KB Output is correct
27 Correct 18 ms 31564 KB Output is correct
28 Correct 17 ms 31588 KB Output is correct
29 Correct 15 ms 31564 KB Output is correct
30 Correct 18 ms 31504 KB Output is correct
31 Correct 15 ms 31536 KB Output is correct
32 Correct 18 ms 31608 KB Output is correct
33 Correct 16 ms 31560 KB Output is correct
34 Correct 17 ms 31564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31544 KB Output is correct
2 Correct 14 ms 31572 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 14 ms 31564 KB Output is correct
5 Correct 19 ms 31592 KB Output is correct
6 Correct 16 ms 31564 KB Output is correct
7 Correct 14 ms 31540 KB Output is correct
8 Correct 15 ms 31564 KB Output is correct
9 Correct 14 ms 31564 KB Output is correct
10 Correct 14 ms 31576 KB Output is correct
11 Correct 14 ms 31580 KB Output is correct
12 Correct 15 ms 31532 KB Output is correct
13 Correct 14 ms 31532 KB Output is correct
14 Correct 19 ms 31592 KB Output is correct
15 Correct 14 ms 31564 KB Output is correct
16 Correct 15 ms 31560 KB Output is correct
17 Correct 14 ms 31516 KB Output is correct
18 Correct 21 ms 31564 KB Output is correct
19 Correct 14 ms 31624 KB Output is correct
20 Correct 14 ms 31564 KB Output is correct
21 Correct 17 ms 31564 KB Output is correct
22 Correct 15 ms 31564 KB Output is correct
23 Correct 14 ms 31564 KB Output is correct
24 Correct 15 ms 31568 KB Output is correct
25 Correct 15 ms 31548 KB Output is correct
26 Correct 15 ms 31564 KB Output is correct
27 Correct 18 ms 31564 KB Output is correct
28 Correct 17 ms 31588 KB Output is correct
29 Correct 15 ms 31564 KB Output is correct
30 Correct 18 ms 31504 KB Output is correct
31 Correct 15 ms 31536 KB Output is correct
32 Correct 18 ms 31608 KB Output is correct
33 Correct 16 ms 31560 KB Output is correct
34 Correct 17 ms 31564 KB Output is correct
35 Correct 14 ms 31564 KB Output is correct
36 Correct 15 ms 31544 KB Output is correct
37 Correct 14 ms 31564 KB Output is correct
38 Correct 16 ms 31628 KB Output is correct
39 Correct 15 ms 31564 KB Output is correct
40 Correct 15 ms 31544 KB Output is correct
41 Correct 15 ms 31564 KB Output is correct
42 Correct 15 ms 31564 KB Output is correct
43 Correct 15 ms 31620 KB Output is correct
44 Correct 19 ms 31564 KB Output is correct
45 Correct 18 ms 31576 KB Output is correct
46 Correct 15 ms 31536 KB Output is correct
47 Correct 15 ms 31532 KB Output is correct
48 Correct 15 ms 31536 KB Output is correct
49 Correct 15 ms 31540 KB Output is correct
50 Correct 14 ms 31564 KB Output is correct
51 Correct 18 ms 31516 KB Output is correct
52 Correct 19 ms 31564 KB Output is correct
53 Correct 15 ms 31564 KB Output is correct
54 Correct 15 ms 31520 KB Output is correct
55 Correct 15 ms 31588 KB Output is correct
56 Correct 17 ms 31564 KB Output is correct
57 Correct 17 ms 31572 KB Output is correct
58 Correct 17 ms 31540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31564 KB Output is correct
2 Correct 15 ms 31564 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 16 ms 31692 KB Output is correct
5 Correct 15 ms 31564 KB Output is correct
6 Correct 15 ms 31528 KB Output is correct
7 Correct 96 ms 33512 KB Output is correct
8 Correct 91 ms 33524 KB Output is correct
9 Correct 92 ms 33576 KB Output is correct
10 Correct 121 ms 33592 KB Output is correct
11 Correct 95 ms 33592 KB Output is correct
12 Correct 93 ms 33524 KB Output is correct
13 Correct 93 ms 33524 KB Output is correct
14 Correct 101 ms 33540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 18 ms 31544 KB Output is correct
2 Correct 14 ms 31572 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 14 ms 31564 KB Output is correct
5 Correct 19 ms 31592 KB Output is correct
6 Correct 16 ms 31564 KB Output is correct
7 Correct 14 ms 31540 KB Output is correct
8 Correct 15 ms 31564 KB Output is correct
9 Correct 14 ms 31564 KB Output is correct
10 Correct 14 ms 31576 KB Output is correct
11 Correct 14 ms 31580 KB Output is correct
12 Correct 15 ms 31532 KB Output is correct
13 Correct 14 ms 31532 KB Output is correct
14 Correct 19 ms 31592 KB Output is correct
15 Correct 14 ms 31564 KB Output is correct
16 Correct 15 ms 31560 KB Output is correct
17 Correct 14 ms 31516 KB Output is correct
18 Correct 21 ms 31564 KB Output is correct
19 Correct 14 ms 31624 KB Output is correct
20 Correct 14 ms 31564 KB Output is correct
21 Correct 17 ms 31564 KB Output is correct
22 Correct 15 ms 31564 KB Output is correct
23 Correct 14 ms 31564 KB Output is correct
24 Correct 15 ms 31568 KB Output is correct
25 Correct 15 ms 31548 KB Output is correct
26 Correct 15 ms 31564 KB Output is correct
27 Correct 18 ms 31564 KB Output is correct
28 Correct 17 ms 31588 KB Output is correct
29 Correct 15 ms 31564 KB Output is correct
30 Correct 18 ms 31504 KB Output is correct
31 Correct 15 ms 31536 KB Output is correct
32 Correct 18 ms 31608 KB Output is correct
33 Correct 16 ms 31560 KB Output is correct
34 Correct 17 ms 31564 KB Output is correct
35 Correct 14 ms 31564 KB Output is correct
36 Correct 15 ms 31544 KB Output is correct
37 Correct 14 ms 31564 KB Output is correct
38 Correct 16 ms 31628 KB Output is correct
39 Correct 15 ms 31564 KB Output is correct
40 Correct 15 ms 31544 KB Output is correct
41 Correct 15 ms 31564 KB Output is correct
42 Correct 15 ms 31564 KB Output is correct
43 Correct 15 ms 31620 KB Output is correct
44 Correct 19 ms 31564 KB Output is correct
45 Correct 18 ms 31576 KB Output is correct
46 Correct 15 ms 31536 KB Output is correct
47 Correct 15 ms 31532 KB Output is correct
48 Correct 15 ms 31536 KB Output is correct
49 Correct 15 ms 31540 KB Output is correct
50 Correct 14 ms 31564 KB Output is correct
51 Correct 18 ms 31516 KB Output is correct
52 Correct 19 ms 31564 KB Output is correct
53 Correct 15 ms 31564 KB Output is correct
54 Correct 15 ms 31520 KB Output is correct
55 Correct 15 ms 31588 KB Output is correct
56 Correct 17 ms 31564 KB Output is correct
57 Correct 17 ms 31572 KB Output is correct
58 Correct 17 ms 31540 KB Output is correct
59 Correct 17 ms 31564 KB Output is correct
60 Correct 15 ms 31564 KB Output is correct
61 Correct 14 ms 31564 KB Output is correct
62 Correct 16 ms 31692 KB Output is correct
63 Correct 15 ms 31564 KB Output is correct
64 Correct 15 ms 31528 KB Output is correct
65 Correct 96 ms 33512 KB Output is correct
66 Correct 91 ms 33524 KB Output is correct
67 Correct 92 ms 33576 KB Output is correct
68 Correct 121 ms 33592 KB Output is correct
69 Correct 95 ms 33592 KB Output is correct
70 Correct 93 ms 33524 KB Output is correct
71 Correct 93 ms 33524 KB Output is correct
72 Correct 101 ms 33540 KB Output is correct
73 Correct 99 ms 33524 KB Output is correct
74 Correct 92 ms 33584 KB Output is correct
75 Correct 94 ms 33492 KB Output is correct
76 Correct 95 ms 33512 KB Output is correct
77 Correct 120 ms 33524 KB Output is correct
78 Correct 92 ms 33508 KB Output is correct
79 Correct 98 ms 33568 KB Output is correct
80 Correct 110 ms 33528 KB Output is correct
81 Correct 93 ms 33528 KB Output is correct
82 Correct 91 ms 33524 KB Output is correct
83 Correct 114 ms 33556 KB Output is correct
84 Correct 109 ms 33524 KB Output is correct
85 Correct 118 ms 33524 KB Output is correct
86 Correct 96 ms 33524 KB Output is correct
87 Correct 109 ms 33508 KB Output is correct
88 Correct 154 ms 33524 KB Output is correct
89 Correct 96 ms 33492 KB Output is correct
90 Correct 100 ms 33552 KB Output is correct
91 Correct 129 ms 33524 KB Output is correct
92 Correct 130 ms 33496 KB Output is correct
93 Correct 103 ms 33516 KB Output is correct
94 Correct 103 ms 33524 KB Output is correct
95 Correct 100 ms 33524 KB Output is correct
96 Correct 121 ms 33520 KB Output is correct
97 Correct 121 ms 33524 KB Output is correct
98 Correct 100 ms 33528 KB Output is correct
99 Correct 100 ms 33540 KB Output is correct
100 Correct 122 ms 33528 KB Output is correct
101 Correct 135 ms 33576 KB Output is correct
102 Correct 103 ms 33572 KB Output is correct