Submission #395894

# Submission time Handle Problem Language Result Execution time Memory
395894 2021-04-29T05:58:59 Z Osama_Alkhodairy Lamps (JOI19_lamps) C++17
100 / 100
238 ms 145452 KB
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

const int N = 1000001;

int n, dp[N][2][2][2];
string a, b;

int calc(int idx, int is_off, int is_on, int is_toggle){
    int ret = a[idx];
    if(is_off) ret = 0;
    if(is_on) ret = 1;
    if(is_toggle) ret ^= 1;
    return ret;
}
int solve(int idx, int is_off, int is_on, int is_toggle){
    if(idx == n) return 0;
    int &ret = dp[idx][is_off][is_on][is_toggle];
    if(ret != -1) return ret;
    ret = (int)1e9;
    for(int x = 0 ; x < 2 ; x++){
        for(int y = 0 ; y < 2 ; y++){
            for(int z = 0 ; z < 2 ; z++){
                if(x && y) continue;
                if(calc(idx, x, y, z) == b[idx]){
                    ret = min(ret, solve(idx + 1, x, y, z) + max(0, x - is_off) + max(0, y - is_on) + max(0, z - is_toggle));
                }
            }
        }
    }
    return ret;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> n >> a >> b;
    for(auto &i : a) i -= '0';
    for(auto &i : b) i -= '0';
    cout << solve(0, 0, 0, 0) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31592 KB Output is correct
2 Correct 16 ms 31584 KB Output is correct
3 Correct 17 ms 31568 KB Output is correct
4 Correct 16 ms 31548 KB Output is correct
5 Correct 17 ms 31564 KB Output is correct
6 Correct 17 ms 31564 KB Output is correct
7 Correct 16 ms 31564 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 17 ms 31604 KB Output is correct
10 Correct 18 ms 31564 KB Output is correct
11 Correct 17 ms 31556 KB Output is correct
12 Correct 16 ms 31632 KB Output is correct
13 Correct 17 ms 31564 KB Output is correct
14 Correct 16 ms 31564 KB Output is correct
15 Correct 18 ms 31632 KB Output is correct
16 Correct 16 ms 31592 KB Output is correct
17 Correct 16 ms 31628 KB Output is correct
18 Correct 16 ms 31564 KB Output is correct
19 Correct 16 ms 31564 KB Output is correct
20 Correct 16 ms 31564 KB Output is correct
21 Correct 16 ms 31616 KB Output is correct
22 Correct 16 ms 31564 KB Output is correct
23 Correct 16 ms 31628 KB Output is correct
24 Correct 16 ms 31628 KB Output is correct
25 Correct 19 ms 31636 KB Output is correct
26 Correct 16 ms 31564 KB Output is correct
27 Correct 16 ms 31524 KB Output is correct
28 Correct 16 ms 31564 KB Output is correct
29 Correct 16 ms 31632 KB Output is correct
30 Correct 17 ms 31564 KB Output is correct
31 Correct 16 ms 31592 KB Output is correct
32 Correct 16 ms 31524 KB Output is correct
33 Correct 16 ms 31588 KB Output is correct
34 Correct 17 ms 31564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31592 KB Output is correct
2 Correct 16 ms 31584 KB Output is correct
3 Correct 17 ms 31568 KB Output is correct
4 Correct 16 ms 31548 KB Output is correct
5 Correct 17 ms 31564 KB Output is correct
6 Correct 17 ms 31564 KB Output is correct
7 Correct 16 ms 31564 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 17 ms 31604 KB Output is correct
10 Correct 18 ms 31564 KB Output is correct
11 Correct 17 ms 31556 KB Output is correct
12 Correct 16 ms 31632 KB Output is correct
13 Correct 17 ms 31564 KB Output is correct
14 Correct 16 ms 31564 KB Output is correct
15 Correct 18 ms 31632 KB Output is correct
16 Correct 16 ms 31592 KB Output is correct
17 Correct 16 ms 31628 KB Output is correct
18 Correct 16 ms 31564 KB Output is correct
19 Correct 16 ms 31564 KB Output is correct
20 Correct 16 ms 31564 KB Output is correct
21 Correct 16 ms 31616 KB Output is correct
22 Correct 16 ms 31564 KB Output is correct
23 Correct 16 ms 31628 KB Output is correct
24 Correct 16 ms 31628 KB Output is correct
25 Correct 19 ms 31636 KB Output is correct
26 Correct 16 ms 31564 KB Output is correct
27 Correct 16 ms 31524 KB Output is correct
28 Correct 16 ms 31564 KB Output is correct
29 Correct 16 ms 31632 KB Output is correct
30 Correct 17 ms 31564 KB Output is correct
31 Correct 16 ms 31592 KB Output is correct
32 Correct 16 ms 31524 KB Output is correct
33 Correct 16 ms 31588 KB Output is correct
34 Correct 17 ms 31564 KB Output is correct
35 Correct 18 ms 31824 KB Output is correct
36 Correct 19 ms 31780 KB Output is correct
37 Correct 17 ms 31760 KB Output is correct
38 Correct 19 ms 31732 KB Output is correct
39 Correct 16 ms 31820 KB Output is correct
40 Correct 17 ms 31744 KB Output is correct
41 Correct 17 ms 31764 KB Output is correct
42 Correct 17 ms 31824 KB Output is correct
43 Correct 17 ms 31820 KB Output is correct
44 Correct 16 ms 31820 KB Output is correct
45 Correct 17 ms 31760 KB Output is correct
46 Correct 17 ms 31776 KB Output is correct
47 Correct 17 ms 31820 KB Output is correct
48 Correct 17 ms 31812 KB Output is correct
49 Correct 16 ms 31756 KB Output is correct
50 Correct 19 ms 31836 KB Output is correct
51 Correct 17 ms 31764 KB Output is correct
52 Correct 17 ms 31756 KB Output is correct
53 Correct 17 ms 31816 KB Output is correct
54 Correct 16 ms 31852 KB Output is correct
55 Correct 16 ms 31820 KB Output is correct
56 Correct 16 ms 31820 KB Output is correct
57 Correct 18 ms 31740 KB Output is correct
58 Correct 16 ms 31820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 31564 KB Output is correct
2 Correct 16 ms 31564 KB Output is correct
3 Correct 16 ms 31560 KB Output is correct
4 Correct 16 ms 31564 KB Output is correct
5 Correct 17 ms 31636 KB Output is correct
6 Correct 16 ms 31540 KB Output is correct
7 Correct 227 ms 145188 KB Output is correct
8 Correct 209 ms 145296 KB Output is correct
9 Correct 207 ms 145336 KB Output is correct
10 Correct 238 ms 145296 KB Output is correct
11 Correct 208 ms 145180 KB Output is correct
12 Correct 206 ms 145248 KB Output is correct
13 Correct 209 ms 145224 KB Output is correct
14 Correct 209 ms 145260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 31592 KB Output is correct
2 Correct 16 ms 31584 KB Output is correct
3 Correct 17 ms 31568 KB Output is correct
4 Correct 16 ms 31548 KB Output is correct
5 Correct 17 ms 31564 KB Output is correct
6 Correct 17 ms 31564 KB Output is correct
7 Correct 16 ms 31564 KB Output is correct
8 Correct 16 ms 31564 KB Output is correct
9 Correct 17 ms 31604 KB Output is correct
10 Correct 18 ms 31564 KB Output is correct
11 Correct 17 ms 31556 KB Output is correct
12 Correct 16 ms 31632 KB Output is correct
13 Correct 17 ms 31564 KB Output is correct
14 Correct 16 ms 31564 KB Output is correct
15 Correct 18 ms 31632 KB Output is correct
16 Correct 16 ms 31592 KB Output is correct
17 Correct 16 ms 31628 KB Output is correct
18 Correct 16 ms 31564 KB Output is correct
19 Correct 16 ms 31564 KB Output is correct
20 Correct 16 ms 31564 KB Output is correct
21 Correct 16 ms 31616 KB Output is correct
22 Correct 16 ms 31564 KB Output is correct
23 Correct 16 ms 31628 KB Output is correct
24 Correct 16 ms 31628 KB Output is correct
25 Correct 19 ms 31636 KB Output is correct
26 Correct 16 ms 31564 KB Output is correct
27 Correct 16 ms 31524 KB Output is correct
28 Correct 16 ms 31564 KB Output is correct
29 Correct 16 ms 31632 KB Output is correct
30 Correct 17 ms 31564 KB Output is correct
31 Correct 16 ms 31592 KB Output is correct
32 Correct 16 ms 31524 KB Output is correct
33 Correct 16 ms 31588 KB Output is correct
34 Correct 17 ms 31564 KB Output is correct
35 Correct 18 ms 31824 KB Output is correct
36 Correct 19 ms 31780 KB Output is correct
37 Correct 17 ms 31760 KB Output is correct
38 Correct 19 ms 31732 KB Output is correct
39 Correct 16 ms 31820 KB Output is correct
40 Correct 17 ms 31744 KB Output is correct
41 Correct 17 ms 31764 KB Output is correct
42 Correct 17 ms 31824 KB Output is correct
43 Correct 17 ms 31820 KB Output is correct
44 Correct 16 ms 31820 KB Output is correct
45 Correct 17 ms 31760 KB Output is correct
46 Correct 17 ms 31776 KB Output is correct
47 Correct 17 ms 31820 KB Output is correct
48 Correct 17 ms 31812 KB Output is correct
49 Correct 16 ms 31756 KB Output is correct
50 Correct 19 ms 31836 KB Output is correct
51 Correct 17 ms 31764 KB Output is correct
52 Correct 17 ms 31756 KB Output is correct
53 Correct 17 ms 31816 KB Output is correct
54 Correct 16 ms 31852 KB Output is correct
55 Correct 16 ms 31820 KB Output is correct
56 Correct 16 ms 31820 KB Output is correct
57 Correct 18 ms 31740 KB Output is correct
58 Correct 16 ms 31820 KB Output is correct
59 Correct 17 ms 31564 KB Output is correct
60 Correct 16 ms 31564 KB Output is correct
61 Correct 16 ms 31560 KB Output is correct
62 Correct 16 ms 31564 KB Output is correct
63 Correct 17 ms 31636 KB Output is correct
64 Correct 16 ms 31540 KB Output is correct
65 Correct 227 ms 145188 KB Output is correct
66 Correct 209 ms 145296 KB Output is correct
67 Correct 207 ms 145336 KB Output is correct
68 Correct 238 ms 145296 KB Output is correct
69 Correct 208 ms 145180 KB Output is correct
70 Correct 206 ms 145248 KB Output is correct
71 Correct 209 ms 145224 KB Output is correct
72 Correct 209 ms 145260 KB Output is correct
73 Correct 217 ms 145264 KB Output is correct
74 Correct 215 ms 145256 KB Output is correct
75 Correct 201 ms 145276 KB Output is correct
76 Correct 214 ms 145260 KB Output is correct
77 Correct 206 ms 145276 KB Output is correct
78 Correct 202 ms 145168 KB Output is correct
79 Correct 216 ms 145208 KB Output is correct
80 Correct 205 ms 145356 KB Output is correct
81 Correct 204 ms 145220 KB Output is correct
82 Correct 212 ms 145296 KB Output is correct
83 Correct 219 ms 145264 KB Output is correct
84 Correct 220 ms 145268 KB Output is correct
85 Correct 221 ms 145380 KB Output is correct
86 Correct 222 ms 145304 KB Output is correct
87 Correct 229 ms 145168 KB Output is correct
88 Correct 224 ms 145264 KB Output is correct
89 Correct 222 ms 145264 KB Output is correct
90 Correct 222 ms 145284 KB Output is correct
91 Correct 228 ms 145248 KB Output is correct
92 Correct 234 ms 145452 KB Output is correct
93 Correct 233 ms 145168 KB Output is correct
94 Correct 234 ms 145248 KB Output is correct
95 Correct 237 ms 145164 KB Output is correct
96 Correct 234 ms 145240 KB Output is correct
97 Correct 235 ms 145212 KB Output is correct
98 Correct 234 ms 145268 KB Output is correct
99 Correct 233 ms 145164 KB Output is correct
100 Correct 231 ms 145176 KB Output is correct
101 Correct 232 ms 145204 KB Output is correct
102 Correct 232 ms 145328 KB Output is correct