Submission #511454

# Submission time Handle Problem Language Result Execution time Memory
511454 2022-01-15T20:53:55 Z couplefire Lamps (JOI19_lamps) C++17
100 / 100
147 ms 122004 KB
#include<bits/stdc++.h>
 
using namespace std;
 
const int MAXN = 1000005;
 
int n, sol = 1e9;
string a, b;
int dp[MAXN][3][2];
 
char f (char c, int tip, int toggle) {
    if (tip == 0) c = '0'; else if (tip == 1) c = '1';
    if (toggle) {
        if (c == '0') c = '1'; else c = '0';
    }
    return c;
}
 
int calc (int pos, int tip, int toggle) {
    if (pos == n) return 0;
    if (dp[pos][tip][toggle] != -1) return dp[pos][tip][toggle];
    int res = 1e9;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 2; j++) {
            int cost = 0;
            if (i <= 1 && tip != i) cost++;
            if (j == 1 && toggle == 0) cost++;
            if (b[pos] == f(a[pos], i, j)) res =  min(res, cost + calc(pos + 1, i, j));
        }
    }
    return dp[pos][tip][toggle] = res;
}
 
int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> a >> b;
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 2; j++) {
            int cost = 0;
            if (i <= 1) cost++;
            if (j == 1) cost++;
            sol = min(sol, cost + calc(0, i, j));
        }
    }
    cout << sol;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23712 KB Output is correct
2 Correct 10 ms 23760 KB Output is correct
3 Correct 9 ms 23756 KB Output is correct
4 Correct 11 ms 23760 KB Output is correct
5 Correct 10 ms 23744 KB Output is correct
6 Correct 10 ms 23756 KB Output is correct
7 Correct 9 ms 23752 KB Output is correct
8 Correct 10 ms 23748 KB Output is correct
9 Correct 9 ms 23756 KB Output is correct
10 Correct 10 ms 23756 KB Output is correct
11 Correct 10 ms 23744 KB Output is correct
12 Correct 13 ms 23756 KB Output is correct
13 Correct 9 ms 23728 KB Output is correct
14 Correct 10 ms 23792 KB Output is correct
15 Correct 9 ms 23752 KB Output is correct
16 Correct 9 ms 23744 KB Output is correct
17 Correct 9 ms 23756 KB Output is correct
18 Correct 9 ms 23744 KB Output is correct
19 Correct 10 ms 23756 KB Output is correct
20 Correct 10 ms 23756 KB Output is correct
21 Correct 9 ms 23744 KB Output is correct
22 Correct 10 ms 23724 KB Output is correct
23 Correct 10 ms 23756 KB Output is correct
24 Correct 10 ms 23756 KB Output is correct
25 Correct 9 ms 23744 KB Output is correct
26 Correct 9 ms 23756 KB Output is correct
27 Correct 11 ms 23736 KB Output is correct
28 Correct 9 ms 23756 KB Output is correct
29 Correct 10 ms 23756 KB Output is correct
30 Correct 12 ms 23756 KB Output is correct
31 Correct 9 ms 23756 KB Output is correct
32 Correct 9 ms 23756 KB Output is correct
33 Correct 9 ms 23756 KB Output is correct
34 Correct 11 ms 23712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23712 KB Output is correct
2 Correct 10 ms 23760 KB Output is correct
3 Correct 9 ms 23756 KB Output is correct
4 Correct 11 ms 23760 KB Output is correct
5 Correct 10 ms 23744 KB Output is correct
6 Correct 10 ms 23756 KB Output is correct
7 Correct 9 ms 23752 KB Output is correct
8 Correct 10 ms 23748 KB Output is correct
9 Correct 9 ms 23756 KB Output is correct
10 Correct 10 ms 23756 KB Output is correct
11 Correct 10 ms 23744 KB Output is correct
12 Correct 13 ms 23756 KB Output is correct
13 Correct 9 ms 23728 KB Output is correct
14 Correct 10 ms 23792 KB Output is correct
15 Correct 9 ms 23752 KB Output is correct
16 Correct 9 ms 23744 KB Output is correct
17 Correct 9 ms 23756 KB Output is correct
18 Correct 9 ms 23744 KB Output is correct
19 Correct 10 ms 23756 KB Output is correct
20 Correct 10 ms 23756 KB Output is correct
21 Correct 9 ms 23744 KB Output is correct
22 Correct 10 ms 23724 KB Output is correct
23 Correct 10 ms 23756 KB Output is correct
24 Correct 10 ms 23756 KB Output is correct
25 Correct 9 ms 23744 KB Output is correct
26 Correct 9 ms 23756 KB Output is correct
27 Correct 11 ms 23736 KB Output is correct
28 Correct 9 ms 23756 KB Output is correct
29 Correct 10 ms 23756 KB Output is correct
30 Correct 12 ms 23756 KB Output is correct
31 Correct 9 ms 23756 KB Output is correct
32 Correct 9 ms 23756 KB Output is correct
33 Correct 9 ms 23756 KB Output is correct
34 Correct 11 ms 23712 KB Output is correct
35 Correct 10 ms 23884 KB Output is correct
36 Correct 9 ms 23952 KB Output is correct
37 Correct 10 ms 23876 KB Output is correct
38 Correct 10 ms 23948 KB Output is correct
39 Correct 9 ms 23884 KB Output is correct
40 Correct 9 ms 23880 KB Output is correct
41 Correct 9 ms 23884 KB Output is correct
42 Correct 10 ms 23884 KB Output is correct
43 Correct 9 ms 23884 KB Output is correct
44 Correct 10 ms 23884 KB Output is correct
45 Correct 10 ms 23972 KB Output is correct
46 Correct 9 ms 23884 KB Output is correct
47 Correct 10 ms 23900 KB Output is correct
48 Correct 9 ms 23884 KB Output is correct
49 Correct 9 ms 23872 KB Output is correct
50 Correct 9 ms 23884 KB Output is correct
51 Correct 10 ms 23936 KB Output is correct
52 Correct 10 ms 23884 KB Output is correct
53 Correct 9 ms 23912 KB Output is correct
54 Correct 10 ms 23884 KB Output is correct
55 Correct 10 ms 23884 KB Output is correct
56 Correct 10 ms 23884 KB Output is correct
57 Correct 12 ms 23884 KB Output is correct
58 Correct 13 ms 24036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23748 KB Output is correct
2 Correct 9 ms 23756 KB Output is correct
3 Correct 9 ms 23740 KB Output is correct
4 Correct 9 ms 23756 KB Output is correct
5 Correct 9 ms 23756 KB Output is correct
6 Correct 9 ms 23756 KB Output is correct
7 Correct 117 ms 121772 KB Output is correct
8 Correct 122 ms 121888 KB Output is correct
9 Correct 128 ms 121712 KB Output is correct
10 Correct 122 ms 121744 KB Output is correct
11 Correct 124 ms 121704 KB Output is correct
12 Correct 121 ms 121764 KB Output is correct
13 Correct 118 ms 121768 KB Output is correct
14 Correct 122 ms 121744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 23712 KB Output is correct
2 Correct 10 ms 23760 KB Output is correct
3 Correct 9 ms 23756 KB Output is correct
4 Correct 11 ms 23760 KB Output is correct
5 Correct 10 ms 23744 KB Output is correct
6 Correct 10 ms 23756 KB Output is correct
7 Correct 9 ms 23752 KB Output is correct
8 Correct 10 ms 23748 KB Output is correct
9 Correct 9 ms 23756 KB Output is correct
10 Correct 10 ms 23756 KB Output is correct
11 Correct 10 ms 23744 KB Output is correct
12 Correct 13 ms 23756 KB Output is correct
13 Correct 9 ms 23728 KB Output is correct
14 Correct 10 ms 23792 KB Output is correct
15 Correct 9 ms 23752 KB Output is correct
16 Correct 9 ms 23744 KB Output is correct
17 Correct 9 ms 23756 KB Output is correct
18 Correct 9 ms 23744 KB Output is correct
19 Correct 10 ms 23756 KB Output is correct
20 Correct 10 ms 23756 KB Output is correct
21 Correct 9 ms 23744 KB Output is correct
22 Correct 10 ms 23724 KB Output is correct
23 Correct 10 ms 23756 KB Output is correct
24 Correct 10 ms 23756 KB Output is correct
25 Correct 9 ms 23744 KB Output is correct
26 Correct 9 ms 23756 KB Output is correct
27 Correct 11 ms 23736 KB Output is correct
28 Correct 9 ms 23756 KB Output is correct
29 Correct 10 ms 23756 KB Output is correct
30 Correct 12 ms 23756 KB Output is correct
31 Correct 9 ms 23756 KB Output is correct
32 Correct 9 ms 23756 KB Output is correct
33 Correct 9 ms 23756 KB Output is correct
34 Correct 11 ms 23712 KB Output is correct
35 Correct 10 ms 23884 KB Output is correct
36 Correct 9 ms 23952 KB Output is correct
37 Correct 10 ms 23876 KB Output is correct
38 Correct 10 ms 23948 KB Output is correct
39 Correct 9 ms 23884 KB Output is correct
40 Correct 9 ms 23880 KB Output is correct
41 Correct 9 ms 23884 KB Output is correct
42 Correct 10 ms 23884 KB Output is correct
43 Correct 9 ms 23884 KB Output is correct
44 Correct 10 ms 23884 KB Output is correct
45 Correct 10 ms 23972 KB Output is correct
46 Correct 9 ms 23884 KB Output is correct
47 Correct 10 ms 23900 KB Output is correct
48 Correct 9 ms 23884 KB Output is correct
49 Correct 9 ms 23872 KB Output is correct
50 Correct 9 ms 23884 KB Output is correct
51 Correct 10 ms 23936 KB Output is correct
52 Correct 10 ms 23884 KB Output is correct
53 Correct 9 ms 23912 KB Output is correct
54 Correct 10 ms 23884 KB Output is correct
55 Correct 10 ms 23884 KB Output is correct
56 Correct 10 ms 23884 KB Output is correct
57 Correct 12 ms 23884 KB Output is correct
58 Correct 13 ms 24036 KB Output is correct
59 Correct 9 ms 23748 KB Output is correct
60 Correct 9 ms 23756 KB Output is correct
61 Correct 9 ms 23740 KB Output is correct
62 Correct 9 ms 23756 KB Output is correct
63 Correct 9 ms 23756 KB Output is correct
64 Correct 9 ms 23756 KB Output is correct
65 Correct 117 ms 121772 KB Output is correct
66 Correct 122 ms 121888 KB Output is correct
67 Correct 128 ms 121712 KB Output is correct
68 Correct 122 ms 121744 KB Output is correct
69 Correct 124 ms 121704 KB Output is correct
70 Correct 121 ms 121764 KB Output is correct
71 Correct 118 ms 121768 KB Output is correct
72 Correct 122 ms 121744 KB Output is correct
73 Correct 121 ms 121732 KB Output is correct
74 Correct 122 ms 121776 KB Output is correct
75 Correct 118 ms 121660 KB Output is correct
76 Correct 118 ms 121736 KB Output is correct
77 Correct 124 ms 121892 KB Output is correct
78 Correct 123 ms 121676 KB Output is correct
79 Correct 124 ms 121748 KB Output is correct
80 Correct 117 ms 122004 KB Output is correct
81 Correct 123 ms 121776 KB Output is correct
82 Correct 126 ms 121656 KB Output is correct
83 Correct 125 ms 121816 KB Output is correct
84 Correct 125 ms 121808 KB Output is correct
85 Correct 127 ms 121688 KB Output is correct
86 Correct 125 ms 121752 KB Output is correct
87 Correct 135 ms 121744 KB Output is correct
88 Correct 125 ms 121880 KB Output is correct
89 Correct 123 ms 121780 KB Output is correct
90 Correct 127 ms 121684 KB Output is correct
91 Correct 138 ms 121860 KB Output is correct
92 Correct 142 ms 121668 KB Output is correct
93 Correct 141 ms 121780 KB Output is correct
94 Correct 143 ms 121668 KB Output is correct
95 Correct 144 ms 121944 KB Output is correct
96 Correct 144 ms 121780 KB Output is correct
97 Correct 147 ms 121872 KB Output is correct
98 Correct 145 ms 121880 KB Output is correct
99 Correct 146 ms 121748 KB Output is correct
100 Correct 143 ms 121776 KB Output is correct
101 Correct 140 ms 121752 KB Output is correct
102 Correct 145 ms 121684 KB Output is correct