Submission #384799

# Submission time Handle Problem Language Result Execution time Memory
384799 2021-04-02T09:46:07 Z kostia244 Lamps (JOI19_lamps) C++17
100 / 100
70 ms 27980 KB
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 12;
int dp[maxn][3][2];
void minq(int &a, int b) {
    a = min(a, b);
}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int n;
    string a, b;
    cin >> n >> a >> b;
    memset(dp, 0x3f, sizeof dp);
    dp[0][0][0] = 0;
    for(int i = 0; i < n; i++) {
        for(int lst = 0; lst < 3; lst++) {
            dp[i][lst][0] = min(dp[i][lst][0], dp[i][lst][1]);
            dp[i][lst][1] = min(dp[i][lst][1], dp[i][lst][0]+1);
            for(int rev = 0; rev < 2; rev++) {
                int cur = (a[i]-'0');
                int targ = (b[i]-'0')^rev;
                if((cur == targ && !lst) || lst-1 == targ)
                    minq(dp[i+1][lst][rev], dp[i][lst][rev]);
                if(cur == targ)
                    minq(dp[i+1][0][rev], dp[i][lst][rev]);
                minq(dp[i+1][1+targ][rev], dp[i][lst][rev]+1);
            }
        }
    }
    int ans = 69<<20;
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 2; j++)
            ans = min(dp[n][i][j], ans);
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 14 ms 23916 KB Output is correct
3 Correct 14 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 14 ms 23788 KB Output is correct
6 Correct 14 ms 23788 KB Output is correct
7 Correct 14 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 14 ms 23788 KB Output is correct
10 Correct 14 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 14 ms 23788 KB Output is correct
13 Correct 14 ms 23788 KB Output is correct
14 Correct 14 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 14 ms 23788 KB Output is correct
18 Correct 14 ms 23788 KB Output is correct
19 Correct 14 ms 23788 KB Output is correct
20 Correct 14 ms 23788 KB Output is correct
21 Correct 13 ms 23788 KB Output is correct
22 Correct 14 ms 23788 KB Output is correct
23 Correct 14 ms 23788 KB Output is correct
24 Correct 13 ms 23788 KB Output is correct
25 Correct 14 ms 23788 KB Output is correct
26 Correct 14 ms 23788 KB Output is correct
27 Correct 14 ms 23788 KB Output is correct
28 Correct 14 ms 23788 KB Output is correct
29 Correct 14 ms 23788 KB Output is correct
30 Correct 14 ms 23788 KB Output is correct
31 Correct 14 ms 23788 KB Output is correct
32 Correct 14 ms 23788 KB Output is correct
33 Correct 14 ms 23788 KB Output is correct
34 Correct 15 ms 23788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 14 ms 23916 KB Output is correct
3 Correct 14 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 14 ms 23788 KB Output is correct
6 Correct 14 ms 23788 KB Output is correct
7 Correct 14 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 14 ms 23788 KB Output is correct
10 Correct 14 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 14 ms 23788 KB Output is correct
13 Correct 14 ms 23788 KB Output is correct
14 Correct 14 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 14 ms 23788 KB Output is correct
18 Correct 14 ms 23788 KB Output is correct
19 Correct 14 ms 23788 KB Output is correct
20 Correct 14 ms 23788 KB Output is correct
21 Correct 13 ms 23788 KB Output is correct
22 Correct 14 ms 23788 KB Output is correct
23 Correct 14 ms 23788 KB Output is correct
24 Correct 13 ms 23788 KB Output is correct
25 Correct 14 ms 23788 KB Output is correct
26 Correct 14 ms 23788 KB Output is correct
27 Correct 14 ms 23788 KB Output is correct
28 Correct 14 ms 23788 KB Output is correct
29 Correct 14 ms 23788 KB Output is correct
30 Correct 14 ms 23788 KB Output is correct
31 Correct 14 ms 23788 KB Output is correct
32 Correct 14 ms 23788 KB Output is correct
33 Correct 14 ms 23788 KB Output is correct
34 Correct 15 ms 23788 KB Output is correct
35 Correct 14 ms 23788 KB Output is correct
36 Correct 14 ms 23788 KB Output is correct
37 Correct 14 ms 23788 KB Output is correct
38 Correct 14 ms 23916 KB Output is correct
39 Correct 15 ms 23920 KB Output is correct
40 Correct 14 ms 23788 KB Output is correct
41 Correct 14 ms 23788 KB Output is correct
42 Correct 14 ms 23788 KB Output is correct
43 Correct 14 ms 23788 KB Output is correct
44 Correct 14 ms 23788 KB Output is correct
45 Correct 14 ms 23788 KB Output is correct
46 Correct 14 ms 23788 KB Output is correct
47 Correct 14 ms 23788 KB Output is correct
48 Correct 14 ms 23788 KB Output is correct
49 Correct 14 ms 23788 KB Output is correct
50 Correct 14 ms 23788 KB Output is correct
51 Correct 17 ms 23788 KB Output is correct
52 Correct 15 ms 23788 KB Output is correct
53 Correct 14 ms 23788 KB Output is correct
54 Correct 14 ms 23788 KB Output is correct
55 Correct 14 ms 23788 KB Output is correct
56 Correct 15 ms 23788 KB Output is correct
57 Correct 14 ms 23788 KB Output is correct
58 Correct 14 ms 23788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 14 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 14 ms 23788 KB Output is correct
6 Correct 14 ms 23916 KB Output is correct
7 Correct 59 ms 26428 KB Output is correct
8 Correct 60 ms 26428 KB Output is correct
9 Correct 60 ms 26428 KB Output is correct
10 Correct 59 ms 26428 KB Output is correct
11 Correct 59 ms 26428 KB Output is correct
12 Correct 60 ms 26428 KB Output is correct
13 Correct 59 ms 26428 KB Output is correct
14 Correct 60 ms 26428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23788 KB Output is correct
2 Correct 14 ms 23916 KB Output is correct
3 Correct 14 ms 23788 KB Output is correct
4 Correct 14 ms 23788 KB Output is correct
5 Correct 14 ms 23788 KB Output is correct
6 Correct 14 ms 23788 KB Output is correct
7 Correct 14 ms 23788 KB Output is correct
8 Correct 14 ms 23788 KB Output is correct
9 Correct 14 ms 23788 KB Output is correct
10 Correct 14 ms 23788 KB Output is correct
11 Correct 14 ms 23788 KB Output is correct
12 Correct 14 ms 23788 KB Output is correct
13 Correct 14 ms 23788 KB Output is correct
14 Correct 14 ms 23788 KB Output is correct
15 Correct 14 ms 23788 KB Output is correct
16 Correct 15 ms 23788 KB Output is correct
17 Correct 14 ms 23788 KB Output is correct
18 Correct 14 ms 23788 KB Output is correct
19 Correct 14 ms 23788 KB Output is correct
20 Correct 14 ms 23788 KB Output is correct
21 Correct 13 ms 23788 KB Output is correct
22 Correct 14 ms 23788 KB Output is correct
23 Correct 14 ms 23788 KB Output is correct
24 Correct 13 ms 23788 KB Output is correct
25 Correct 14 ms 23788 KB Output is correct
26 Correct 14 ms 23788 KB Output is correct
27 Correct 14 ms 23788 KB Output is correct
28 Correct 14 ms 23788 KB Output is correct
29 Correct 14 ms 23788 KB Output is correct
30 Correct 14 ms 23788 KB Output is correct
31 Correct 14 ms 23788 KB Output is correct
32 Correct 14 ms 23788 KB Output is correct
33 Correct 14 ms 23788 KB Output is correct
34 Correct 15 ms 23788 KB Output is correct
35 Correct 14 ms 23788 KB Output is correct
36 Correct 14 ms 23788 KB Output is correct
37 Correct 14 ms 23788 KB Output is correct
38 Correct 14 ms 23916 KB Output is correct
39 Correct 15 ms 23920 KB Output is correct
40 Correct 14 ms 23788 KB Output is correct
41 Correct 14 ms 23788 KB Output is correct
42 Correct 14 ms 23788 KB Output is correct
43 Correct 14 ms 23788 KB Output is correct
44 Correct 14 ms 23788 KB Output is correct
45 Correct 14 ms 23788 KB Output is correct
46 Correct 14 ms 23788 KB Output is correct
47 Correct 14 ms 23788 KB Output is correct
48 Correct 14 ms 23788 KB Output is correct
49 Correct 14 ms 23788 KB Output is correct
50 Correct 14 ms 23788 KB Output is correct
51 Correct 17 ms 23788 KB Output is correct
52 Correct 15 ms 23788 KB Output is correct
53 Correct 14 ms 23788 KB Output is correct
54 Correct 14 ms 23788 KB Output is correct
55 Correct 14 ms 23788 KB Output is correct
56 Correct 15 ms 23788 KB Output is correct
57 Correct 14 ms 23788 KB Output is correct
58 Correct 14 ms 23788 KB Output is correct
59 Correct 14 ms 23788 KB Output is correct
60 Correct 15 ms 23788 KB Output is correct
61 Correct 14 ms 23788 KB Output is correct
62 Correct 14 ms 23788 KB Output is correct
63 Correct 14 ms 23788 KB Output is correct
64 Correct 14 ms 23916 KB Output is correct
65 Correct 59 ms 26428 KB Output is correct
66 Correct 60 ms 26428 KB Output is correct
67 Correct 60 ms 26428 KB Output is correct
68 Correct 59 ms 26428 KB Output is correct
69 Correct 59 ms 26428 KB Output is correct
70 Correct 60 ms 26428 KB Output is correct
71 Correct 59 ms 26428 KB Output is correct
72 Correct 60 ms 26428 KB Output is correct
73 Correct 61 ms 27836 KB Output is correct
74 Correct 60 ms 27836 KB Output is correct
75 Correct 61 ms 27964 KB Output is correct
76 Correct 61 ms 27980 KB Output is correct
77 Correct 60 ms 27836 KB Output is correct
78 Correct 60 ms 27836 KB Output is correct
79 Correct 61 ms 27964 KB Output is correct
80 Correct 62 ms 27964 KB Output is correct
81 Correct 60 ms 27836 KB Output is correct
82 Correct 60 ms 27964 KB Output is correct
83 Correct 64 ms 27964 KB Output is correct
84 Correct 64 ms 27836 KB Output is correct
85 Correct 64 ms 27836 KB Output is correct
86 Correct 64 ms 27836 KB Output is correct
87 Correct 67 ms 27836 KB Output is correct
88 Correct 66 ms 27836 KB Output is correct
89 Correct 65 ms 27836 KB Output is correct
90 Correct 65 ms 27836 KB Output is correct
91 Correct 66 ms 27836 KB Output is correct
92 Correct 67 ms 27836 KB Output is correct
93 Correct 68 ms 27836 KB Output is correct
94 Correct 69 ms 27836 KB Output is correct
95 Correct 68 ms 27836 KB Output is correct
96 Correct 68 ms 27836 KB Output is correct
97 Correct 68 ms 27964 KB Output is correct
98 Correct 70 ms 27836 KB Output is correct
99 Correct 69 ms 27964 KB Output is correct
100 Correct 69 ms 27836 KB Output is correct
101 Correct 69 ms 27836 KB Output is correct
102 Correct 68 ms 27964 KB Output is correct