Submission #428841

# Submission time Handle Problem Language Result Execution time Memory
428841 2021-06-15T14:48:46 Z tengiz05 Lamps (JOI19_lamps) C++17
100 / 100
149 ms 35604 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;
    // [pos][0][1][xor]
    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++) {
                                int cost = dp[i - 1][A0][A1][XR];
                                if (a0 > A0) cost++;
                                if (a1 > A1) cost++;
                                if (xr > XR) cost++;
                                ret = std::min(ret, cost);
                            }
                        }
                    }
                }
    }
    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 16 ms 31564 KB Output is correct
2 Correct 14 ms 31564 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 15 ms 31564 KB Output is correct
5 Correct 15 ms 31564 KB Output is correct
6 Correct 15 ms 31564 KB Output is correct
7 Correct 15 ms 31564 KB Output is correct
8 Correct 14 ms 31564 KB Output is correct
9 Correct 18 ms 31592 KB Output is correct
10 Correct 14 ms 31564 KB Output is correct
11 Correct 15 ms 31564 KB Output is correct
12 Correct 15 ms 31564 KB Output is correct
13 Correct 15 ms 31608 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 17 ms 31624 KB Output is correct
16 Correct 14 ms 31528 KB Output is correct
17 Correct 17 ms 31628 KB Output is correct
18 Correct 15 ms 31552 KB Output is correct
19 Correct 15 ms 31564 KB Output is correct
20 Correct 14 ms 31564 KB Output is correct
21 Correct 14 ms 31564 KB Output is correct
22 Correct 14 ms 31564 KB Output is correct
23 Correct 14 ms 31548 KB Output is correct
24 Correct 14 ms 31556 KB Output is correct
25 Correct 16 ms 31560 KB Output is correct
26 Correct 17 ms 31540 KB Output is correct
27 Correct 16 ms 31564 KB Output is correct
28 Correct 16 ms 31588 KB Output is correct
29 Correct 14 ms 31564 KB Output is correct
30 Correct 14 ms 31608 KB Output is correct
31 Correct 15 ms 31592 KB Output is correct
32 Correct 15 ms 31604 KB Output is correct
33 Correct 14 ms 31564 KB Output is correct
34 Correct 14 ms 31564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31564 KB Output is correct
2 Correct 14 ms 31564 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 15 ms 31564 KB Output is correct
5 Correct 15 ms 31564 KB Output is correct
6 Correct 15 ms 31564 KB Output is correct
7 Correct 15 ms 31564 KB Output is correct
8 Correct 14 ms 31564 KB Output is correct
9 Correct 18 ms 31592 KB Output is correct
10 Correct 14 ms 31564 KB Output is correct
11 Correct 15 ms 31564 KB Output is correct
12 Correct 15 ms 31564 KB Output is correct
13 Correct 15 ms 31608 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 17 ms 31624 KB Output is correct
16 Correct 14 ms 31528 KB Output is correct
17 Correct 17 ms 31628 KB Output is correct
18 Correct 15 ms 31552 KB Output is correct
19 Correct 15 ms 31564 KB Output is correct
20 Correct 14 ms 31564 KB Output is correct
21 Correct 14 ms 31564 KB Output is correct
22 Correct 14 ms 31564 KB Output is correct
23 Correct 14 ms 31548 KB Output is correct
24 Correct 14 ms 31556 KB Output is correct
25 Correct 16 ms 31560 KB Output is correct
26 Correct 17 ms 31540 KB Output is correct
27 Correct 16 ms 31564 KB Output is correct
28 Correct 16 ms 31588 KB Output is correct
29 Correct 14 ms 31564 KB Output is correct
30 Correct 14 ms 31608 KB Output is correct
31 Correct 15 ms 31592 KB Output is correct
32 Correct 15 ms 31604 KB Output is correct
33 Correct 14 ms 31564 KB Output is correct
34 Correct 14 ms 31564 KB Output is correct
35 Correct 15 ms 31544 KB Output is correct
36 Correct 14 ms 31564 KB Output is correct
37 Correct 15 ms 31564 KB Output is correct
38 Correct 15 ms 31564 KB Output is correct
39 Correct 15 ms 31564 KB Output is correct
40 Correct 15 ms 31564 KB Output is correct
41 Correct 15 ms 31524 KB Output is correct
42 Correct 17 ms 31608 KB Output is correct
43 Correct 14 ms 31564 KB Output is correct
44 Correct 16 ms 31560 KB Output is correct
45 Correct 15 ms 31544 KB Output is correct
46 Correct 15 ms 31536 KB Output is correct
47 Correct 18 ms 31564 KB Output is correct
48 Correct 16 ms 31620 KB Output is correct
49 Correct 15 ms 31564 KB Output is correct
50 Correct 15 ms 31620 KB Output is correct
51 Correct 15 ms 31560 KB Output is correct
52 Correct 15 ms 31640 KB Output is correct
53 Correct 14 ms 31564 KB Output is correct
54 Correct 14 ms 31596 KB Output is correct
55 Correct 15 ms 31600 KB Output is correct
56 Correct 15 ms 31540 KB Output is correct
57 Correct 15 ms 31564 KB Output is correct
58 Correct 15 ms 31564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 31564 KB Output is correct
2 Correct 14 ms 31596 KB Output is correct
3 Correct 16 ms 31564 KB Output is correct
4 Correct 15 ms 31568 KB Output is correct
5 Correct 15 ms 31600 KB Output is correct
6 Correct 15 ms 31568 KB Output is correct
7 Correct 117 ms 33556 KB Output is correct
8 Correct 120 ms 33588 KB Output is correct
9 Correct 87 ms 33528 KB Output is correct
10 Correct 89 ms 33572 KB Output is correct
11 Correct 87 ms 33528 KB Output is correct
12 Correct 91 ms 33528 KB Output is correct
13 Correct 98 ms 33544 KB Output is correct
14 Correct 91 ms 33568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31564 KB Output is correct
2 Correct 14 ms 31564 KB Output is correct
3 Correct 14 ms 31564 KB Output is correct
4 Correct 15 ms 31564 KB Output is correct
5 Correct 15 ms 31564 KB Output is correct
6 Correct 15 ms 31564 KB Output is correct
7 Correct 15 ms 31564 KB Output is correct
8 Correct 14 ms 31564 KB Output is correct
9 Correct 18 ms 31592 KB Output is correct
10 Correct 14 ms 31564 KB Output is correct
11 Correct 15 ms 31564 KB Output is correct
12 Correct 15 ms 31564 KB Output is correct
13 Correct 15 ms 31608 KB Output is correct
14 Correct 17 ms 31552 KB Output is correct
15 Correct 17 ms 31624 KB Output is correct
16 Correct 14 ms 31528 KB Output is correct
17 Correct 17 ms 31628 KB Output is correct
18 Correct 15 ms 31552 KB Output is correct
19 Correct 15 ms 31564 KB Output is correct
20 Correct 14 ms 31564 KB Output is correct
21 Correct 14 ms 31564 KB Output is correct
22 Correct 14 ms 31564 KB Output is correct
23 Correct 14 ms 31548 KB Output is correct
24 Correct 14 ms 31556 KB Output is correct
25 Correct 16 ms 31560 KB Output is correct
26 Correct 17 ms 31540 KB Output is correct
27 Correct 16 ms 31564 KB Output is correct
28 Correct 16 ms 31588 KB Output is correct
29 Correct 14 ms 31564 KB Output is correct
30 Correct 14 ms 31608 KB Output is correct
31 Correct 15 ms 31592 KB Output is correct
32 Correct 15 ms 31604 KB Output is correct
33 Correct 14 ms 31564 KB Output is correct
34 Correct 14 ms 31564 KB Output is correct
35 Correct 15 ms 31544 KB Output is correct
36 Correct 14 ms 31564 KB Output is correct
37 Correct 15 ms 31564 KB Output is correct
38 Correct 15 ms 31564 KB Output is correct
39 Correct 15 ms 31564 KB Output is correct
40 Correct 15 ms 31564 KB Output is correct
41 Correct 15 ms 31524 KB Output is correct
42 Correct 17 ms 31608 KB Output is correct
43 Correct 14 ms 31564 KB Output is correct
44 Correct 16 ms 31560 KB Output is correct
45 Correct 15 ms 31544 KB Output is correct
46 Correct 15 ms 31536 KB Output is correct
47 Correct 18 ms 31564 KB Output is correct
48 Correct 16 ms 31620 KB Output is correct
49 Correct 15 ms 31564 KB Output is correct
50 Correct 15 ms 31620 KB Output is correct
51 Correct 15 ms 31560 KB Output is correct
52 Correct 15 ms 31640 KB Output is correct
53 Correct 14 ms 31564 KB Output is correct
54 Correct 14 ms 31596 KB Output is correct
55 Correct 15 ms 31600 KB Output is correct
56 Correct 15 ms 31540 KB Output is correct
57 Correct 15 ms 31564 KB Output is correct
58 Correct 15 ms 31564 KB Output is correct
59 Correct 15 ms 31564 KB Output is correct
60 Correct 14 ms 31596 KB Output is correct
61 Correct 16 ms 31564 KB Output is correct
62 Correct 15 ms 31568 KB Output is correct
63 Correct 15 ms 31600 KB Output is correct
64 Correct 15 ms 31568 KB Output is correct
65 Correct 117 ms 33556 KB Output is correct
66 Correct 120 ms 33588 KB Output is correct
67 Correct 87 ms 33528 KB Output is correct
68 Correct 89 ms 33572 KB Output is correct
69 Correct 87 ms 33528 KB Output is correct
70 Correct 91 ms 33528 KB Output is correct
71 Correct 98 ms 33544 KB Output is correct
72 Correct 91 ms 33568 KB Output is correct
73 Correct 111 ms 35444 KB Output is correct
74 Correct 110 ms 35444 KB Output is correct
75 Correct 90 ms 35440 KB Output is correct
76 Correct 90 ms 35564 KB Output is correct
77 Correct 96 ms 35500 KB Output is correct
78 Correct 90 ms 35444 KB Output is correct
79 Correct 103 ms 35544 KB Output is correct
80 Correct 93 ms 35496 KB Output is correct
81 Correct 91 ms 35448 KB Output is correct
82 Correct 94 ms 35604 KB Output is correct
83 Correct 123 ms 35444 KB Output is correct
84 Correct 112 ms 35512 KB Output is correct
85 Correct 94 ms 35444 KB Output is correct
86 Correct 95 ms 35512 KB Output is correct
87 Correct 132 ms 35444 KB Output is correct
88 Correct 111 ms 35512 KB Output is correct
89 Correct 149 ms 35488 KB Output is correct
90 Correct 96 ms 35448 KB Output is correct
91 Correct 106 ms 35444 KB Output is correct
92 Correct 142 ms 35528 KB Output is correct
93 Correct 99 ms 35480 KB Output is correct
94 Correct 104 ms 35572 KB Output is correct
95 Correct 119 ms 35524 KB Output is correct
96 Correct 134 ms 35428 KB Output is correct
97 Correct 108 ms 35572 KB Output is correct
98 Correct 102 ms 35552 KB Output is correct
99 Correct 100 ms 35576 KB Output is correct
100 Correct 113 ms 35544 KB Output is correct
101 Correct 102 ms 35500 KB Output is correct
102 Correct 101 ms 35476 KB Output is correct