Submission #529460

# Submission time Handle Problem Language Result Execution time Memory
529460 2022-02-23T03:31:24 Z 4fecta Lamps (JOI19_lamps) C++17
100 / 100
119 ms 51316 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define ld long double
#define pii pair<int, int>
#define f first
#define s second
#define boost() cin.tie(0), cin.sync_with_stdio(0)

const int MN = 1000005;

int n, dp[MN][3][2];
char a[MN], b[MN];

int32_t main() {
    boost();

    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) cin >> b[i];
    memset(dp, 0x3f, sizeof(dp));
    dp[0][2][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 2; k++) {
                for (int pj = 0; pj < 3; pj++) {
                    for (int pk = 0; pk < 2; pk++) {
                        int cur = j == 2 ? a[i] - '0' : j, tgt = (b[i] - '0') ^ k;
                        if (cur != tgt) continue;
                        int cost = 0;
                        if (j < 2 && j != pj) cost++;
                        if (k && !pk) cost++;
                        dp[i][j][k] = min(dp[i][j][k], dp[i - 1][pj][pk] + cost);
                    }
                }
            }
        }
    }
    int ans = 0x3f3f3f3f;
    for (int j = 0; j < 3; j++) for (int k = 0; k < 2; k++) ans = min(ans, dp[n][j][k]);
    printf("%lld\n", ans);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 19 ms 47172 KB Output is correct
2 Correct 19 ms 47244 KB Output is correct
3 Correct 20 ms 47172 KB Output is correct
4 Correct 19 ms 47272 KB Output is correct
5 Correct 19 ms 47288 KB Output is correct
6 Correct 19 ms 47172 KB Output is correct
7 Correct 20 ms 47184 KB Output is correct
8 Correct 20 ms 47264 KB Output is correct
9 Correct 21 ms 47180 KB Output is correct
10 Correct 20 ms 47292 KB Output is correct
11 Correct 21 ms 47228 KB Output is correct
12 Correct 19 ms 47180 KB Output is correct
13 Correct 20 ms 47172 KB Output is correct
14 Correct 19 ms 47296 KB Output is correct
15 Correct 19 ms 47240 KB Output is correct
16 Correct 19 ms 47216 KB Output is correct
17 Correct 19 ms 47204 KB Output is correct
18 Correct 19 ms 47180 KB Output is correct
19 Correct 19 ms 47172 KB Output is correct
20 Correct 19 ms 47268 KB Output is correct
21 Correct 19 ms 47296 KB Output is correct
22 Correct 26 ms 47296 KB Output is correct
23 Correct 19 ms 47296 KB Output is correct
24 Correct 19 ms 47180 KB Output is correct
25 Correct 19 ms 47180 KB Output is correct
26 Correct 19 ms 47212 KB Output is correct
27 Correct 20 ms 47232 KB Output is correct
28 Correct 20 ms 47180 KB Output is correct
29 Correct 19 ms 47180 KB Output is correct
30 Correct 19 ms 47292 KB Output is correct
31 Correct 20 ms 47180 KB Output is correct
32 Correct 25 ms 47180 KB Output is correct
33 Correct 20 ms 47180 KB Output is correct
34 Correct 20 ms 47300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 47172 KB Output is correct
2 Correct 19 ms 47244 KB Output is correct
3 Correct 20 ms 47172 KB Output is correct
4 Correct 19 ms 47272 KB Output is correct
5 Correct 19 ms 47288 KB Output is correct
6 Correct 19 ms 47172 KB Output is correct
7 Correct 20 ms 47184 KB Output is correct
8 Correct 20 ms 47264 KB Output is correct
9 Correct 21 ms 47180 KB Output is correct
10 Correct 20 ms 47292 KB Output is correct
11 Correct 21 ms 47228 KB Output is correct
12 Correct 19 ms 47180 KB Output is correct
13 Correct 20 ms 47172 KB Output is correct
14 Correct 19 ms 47296 KB Output is correct
15 Correct 19 ms 47240 KB Output is correct
16 Correct 19 ms 47216 KB Output is correct
17 Correct 19 ms 47204 KB Output is correct
18 Correct 19 ms 47180 KB Output is correct
19 Correct 19 ms 47172 KB Output is correct
20 Correct 19 ms 47268 KB Output is correct
21 Correct 19 ms 47296 KB Output is correct
22 Correct 26 ms 47296 KB Output is correct
23 Correct 19 ms 47296 KB Output is correct
24 Correct 19 ms 47180 KB Output is correct
25 Correct 19 ms 47180 KB Output is correct
26 Correct 19 ms 47212 KB Output is correct
27 Correct 20 ms 47232 KB Output is correct
28 Correct 20 ms 47180 KB Output is correct
29 Correct 19 ms 47180 KB Output is correct
30 Correct 19 ms 47292 KB Output is correct
31 Correct 20 ms 47180 KB Output is correct
32 Correct 25 ms 47180 KB Output is correct
33 Correct 20 ms 47180 KB Output is correct
34 Correct 20 ms 47300 KB Output is correct
35 Correct 20 ms 47304 KB Output is correct
36 Correct 19 ms 47240 KB Output is correct
37 Correct 19 ms 47180 KB Output is correct
38 Correct 20 ms 47180 KB Output is correct
39 Correct 19 ms 47180 KB Output is correct
40 Correct 21 ms 47240 KB Output is correct
41 Correct 25 ms 47300 KB Output is correct
42 Correct 19 ms 47180 KB Output is correct
43 Correct 22 ms 47224 KB Output is correct
44 Correct 20 ms 47240 KB Output is correct
45 Correct 19 ms 47180 KB Output is correct
46 Correct 21 ms 47216 KB Output is correct
47 Correct 21 ms 47392 KB Output is correct
48 Correct 20 ms 47236 KB Output is correct
49 Correct 20 ms 47200 KB Output is correct
50 Correct 20 ms 47300 KB Output is correct
51 Correct 22 ms 47180 KB Output is correct
52 Correct 20 ms 47212 KB Output is correct
53 Correct 20 ms 47192 KB Output is correct
54 Correct 19 ms 47212 KB Output is correct
55 Correct 19 ms 47276 KB Output is correct
56 Correct 19 ms 47172 KB Output is correct
57 Correct 19 ms 47180 KB Output is correct
58 Correct 19 ms 47188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 47264 KB Output is correct
2 Correct 19 ms 47248 KB Output is correct
3 Correct 25 ms 47180 KB Output is correct
4 Correct 19 ms 47276 KB Output is correct
5 Correct 21 ms 47292 KB Output is correct
6 Correct 19 ms 47276 KB Output is correct
7 Correct 97 ms 51140 KB Output is correct
8 Correct 102 ms 51316 KB Output is correct
9 Correct 99 ms 51108 KB Output is correct
10 Correct 99 ms 51184 KB Output is correct
11 Correct 103 ms 51176 KB Output is correct
12 Correct 99 ms 51092 KB Output is correct
13 Correct 103 ms 51140 KB Output is correct
14 Correct 100 ms 51104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 47172 KB Output is correct
2 Correct 19 ms 47244 KB Output is correct
3 Correct 20 ms 47172 KB Output is correct
4 Correct 19 ms 47272 KB Output is correct
5 Correct 19 ms 47288 KB Output is correct
6 Correct 19 ms 47172 KB Output is correct
7 Correct 20 ms 47184 KB Output is correct
8 Correct 20 ms 47264 KB Output is correct
9 Correct 21 ms 47180 KB Output is correct
10 Correct 20 ms 47292 KB Output is correct
11 Correct 21 ms 47228 KB Output is correct
12 Correct 19 ms 47180 KB Output is correct
13 Correct 20 ms 47172 KB Output is correct
14 Correct 19 ms 47296 KB Output is correct
15 Correct 19 ms 47240 KB Output is correct
16 Correct 19 ms 47216 KB Output is correct
17 Correct 19 ms 47204 KB Output is correct
18 Correct 19 ms 47180 KB Output is correct
19 Correct 19 ms 47172 KB Output is correct
20 Correct 19 ms 47268 KB Output is correct
21 Correct 19 ms 47296 KB Output is correct
22 Correct 26 ms 47296 KB Output is correct
23 Correct 19 ms 47296 KB Output is correct
24 Correct 19 ms 47180 KB Output is correct
25 Correct 19 ms 47180 KB Output is correct
26 Correct 19 ms 47212 KB Output is correct
27 Correct 20 ms 47232 KB Output is correct
28 Correct 20 ms 47180 KB Output is correct
29 Correct 19 ms 47180 KB Output is correct
30 Correct 19 ms 47292 KB Output is correct
31 Correct 20 ms 47180 KB Output is correct
32 Correct 25 ms 47180 KB Output is correct
33 Correct 20 ms 47180 KB Output is correct
34 Correct 20 ms 47300 KB Output is correct
35 Correct 20 ms 47304 KB Output is correct
36 Correct 19 ms 47240 KB Output is correct
37 Correct 19 ms 47180 KB Output is correct
38 Correct 20 ms 47180 KB Output is correct
39 Correct 19 ms 47180 KB Output is correct
40 Correct 21 ms 47240 KB Output is correct
41 Correct 25 ms 47300 KB Output is correct
42 Correct 19 ms 47180 KB Output is correct
43 Correct 22 ms 47224 KB Output is correct
44 Correct 20 ms 47240 KB Output is correct
45 Correct 19 ms 47180 KB Output is correct
46 Correct 21 ms 47216 KB Output is correct
47 Correct 21 ms 47392 KB Output is correct
48 Correct 20 ms 47236 KB Output is correct
49 Correct 20 ms 47200 KB Output is correct
50 Correct 20 ms 47300 KB Output is correct
51 Correct 22 ms 47180 KB Output is correct
52 Correct 20 ms 47212 KB Output is correct
53 Correct 20 ms 47192 KB Output is correct
54 Correct 19 ms 47212 KB Output is correct
55 Correct 19 ms 47276 KB Output is correct
56 Correct 19 ms 47172 KB Output is correct
57 Correct 19 ms 47180 KB Output is correct
58 Correct 19 ms 47188 KB Output is correct
59 Correct 20 ms 47264 KB Output is correct
60 Correct 19 ms 47248 KB Output is correct
61 Correct 25 ms 47180 KB Output is correct
62 Correct 19 ms 47276 KB Output is correct
63 Correct 21 ms 47292 KB Output is correct
64 Correct 19 ms 47276 KB Output is correct
65 Correct 97 ms 51140 KB Output is correct
66 Correct 102 ms 51316 KB Output is correct
67 Correct 99 ms 51108 KB Output is correct
68 Correct 99 ms 51184 KB Output is correct
69 Correct 103 ms 51176 KB Output is correct
70 Correct 99 ms 51092 KB Output is correct
71 Correct 103 ms 51140 KB Output is correct
72 Correct 100 ms 51104 KB Output is correct
73 Correct 107 ms 51184 KB Output is correct
74 Correct 99 ms 51112 KB Output is correct
75 Correct 99 ms 51140 KB Output is correct
76 Correct 102 ms 51140 KB Output is correct
77 Correct 99 ms 51088 KB Output is correct
78 Correct 101 ms 51084 KB Output is correct
79 Correct 102 ms 51184 KB Output is correct
80 Correct 97 ms 51180 KB Output is correct
81 Correct 96 ms 51124 KB Output is correct
82 Correct 119 ms 51140 KB Output is correct
83 Correct 102 ms 51108 KB Output is correct
84 Correct 103 ms 51140 KB Output is correct
85 Correct 101 ms 51140 KB Output is correct
86 Correct 101 ms 51180 KB Output is correct
87 Correct 103 ms 51212 KB Output is correct
88 Correct 102 ms 51268 KB Output is correct
89 Correct 110 ms 51132 KB Output is correct
90 Correct 99 ms 51088 KB Output is correct
91 Correct 108 ms 51148 KB Output is correct
92 Correct 105 ms 51180 KB Output is correct
93 Correct 105 ms 51140 KB Output is correct
94 Correct 103 ms 51176 KB Output is correct
95 Correct 107 ms 51268 KB Output is correct
96 Correct 106 ms 51176 KB Output is correct
97 Correct 103 ms 51100 KB Output is correct
98 Correct 103 ms 51180 KB Output is correct
99 Correct 103 ms 51212 KB Output is correct
100 Correct 104 ms 51220 KB Output is correct
101 Correct 102 ms 51140 KB Output is correct
102 Correct 104 ms 51176 KB Output is correct