Submission #792462

# Submission time Handle Problem Language Result Execution time Memory
792462 2023-07-25T05:12:10 Z vjudge1 Lamps (JOI19_lamps) C++17
100 / 100
152 ms 27800 KB
#include <bits/stdc++.h>
 
#define fi first
#define se second
 
const int N = 1000010;
 
using namespace std;
 
int n;
int A[N], B[N], C[N], D[N];
char a[N], b[N];
int d[N][3][2];
 
void upd(int &x, int y)
{
        x = min(x, y);
}
 
int main()
{
        ios_base::sync_with_stdio(0);
 
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
 
        cin >> n;
        for(int i = 1; i <= n; i++) cin >> a[i];
        for(int i = 1; i <= n; i++) cin >> b[i];
 
        int inf = 1e9;
        for(int i = 0; i < N; i++){
                for(int j = 0; j < 3; j++){
                        for(int h = 0; h < 2; h++){
                                d[i][j][h] = inf;
                        }
                }
        }
        d[0][0][0] = 0;
        for(int i = 1; i <= n; i++){
                for(int g1 = 0; g1 < 3; g1++){
                        for(int g2 = 0; g2 < 2; g2++){
                                upd(d[i][g1][g2], d[i - 1][g1][g2]);
                                upd(d[i][0][g2], d[i - 1][g1][g2]);
                                upd(d[i][g1][0], d[i - 1][g1][g2]);
                                upd(d[i][0][0], d[i - 1][g1][g2]);
                                if(g1 == 0){
                                        upd(d[i][1][g2], d[i - 1][g1][g2] + 1);
                                        upd(d[i][2][g2], d[i - 1][g1][g2] + 1);
                                        if(g2 == 0){
                                                upd(d[i][1][1], d[i - 1][g1][g2] + 2);
                                                upd(d[i][2][1], d[i - 1][g1][g2] + 2);
                                        }
                                }
                                if(g2 == 0){
                                        upd(d[i][g1][1], d[i - 1][g1][g2] + 1);
                                }
                        }
                }
                for(int g1 = 0; g1 < 3; g1++){
                        for(int g2 = 0; g2 < 2; g2++){
                                int cur = a[i] - '0', need = b[i] - '0';
                                if(g1 == 1) cur = 1;
                                else if(g1 == 2) cur = 0;
                                if(g2 == 1) cur ^= 1;
                                if(cur != need){
                                        d[i][g1][g2] = inf;
                                }
                        }
                }
        }
        int res = inf;
        for(int i = 0; i < 3; i++){
                for(int j = 0; j < 2; j++){
                        res = min(res, d[n][i][j]);
                }
        }
        cout << res << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23780 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 9 ms 23764 KB Output is correct
4 Correct 11 ms 23716 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 10 ms 23728 KB Output is correct
7 Correct 10 ms 23756 KB Output is correct
8 Correct 11 ms 23820 KB Output is correct
9 Correct 10 ms 23764 KB Output is correct
10 Correct 10 ms 23752 KB Output is correct
11 Correct 11 ms 23804 KB Output is correct
12 Correct 11 ms 23752 KB Output is correct
13 Correct 10 ms 23756 KB Output is correct
14 Correct 11 ms 23756 KB Output is correct
15 Correct 10 ms 23736 KB Output is correct
16 Correct 12 ms 23752 KB Output is correct
17 Correct 12 ms 23760 KB Output is correct
18 Correct 9 ms 23764 KB Output is correct
19 Correct 9 ms 23792 KB Output is correct
20 Correct 9 ms 23764 KB Output is correct
21 Correct 9 ms 23748 KB Output is correct
22 Correct 9 ms 23796 KB Output is correct
23 Correct 10 ms 23788 KB Output is correct
24 Correct 9 ms 23712 KB Output is correct
25 Correct 12 ms 23756 KB Output is correct
26 Correct 9 ms 23812 KB Output is correct
27 Correct 9 ms 23760 KB Output is correct
28 Correct 9 ms 23752 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 10 ms 23772 KB Output is correct
31 Correct 26 ms 23684 KB Output is correct
32 Correct 23 ms 23720 KB Output is correct
33 Correct 19 ms 23788 KB Output is correct
34 Correct 13 ms 23752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23780 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 9 ms 23764 KB Output is correct
4 Correct 11 ms 23716 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 10 ms 23728 KB Output is correct
7 Correct 10 ms 23756 KB Output is correct
8 Correct 11 ms 23820 KB Output is correct
9 Correct 10 ms 23764 KB Output is correct
10 Correct 10 ms 23752 KB Output is correct
11 Correct 11 ms 23804 KB Output is correct
12 Correct 11 ms 23752 KB Output is correct
13 Correct 10 ms 23756 KB Output is correct
14 Correct 11 ms 23756 KB Output is correct
15 Correct 10 ms 23736 KB Output is correct
16 Correct 12 ms 23752 KB Output is correct
17 Correct 12 ms 23760 KB Output is correct
18 Correct 9 ms 23764 KB Output is correct
19 Correct 9 ms 23792 KB Output is correct
20 Correct 9 ms 23764 KB Output is correct
21 Correct 9 ms 23748 KB Output is correct
22 Correct 9 ms 23796 KB Output is correct
23 Correct 10 ms 23788 KB Output is correct
24 Correct 9 ms 23712 KB Output is correct
25 Correct 12 ms 23756 KB Output is correct
26 Correct 9 ms 23812 KB Output is correct
27 Correct 9 ms 23760 KB Output is correct
28 Correct 9 ms 23752 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 10 ms 23772 KB Output is correct
31 Correct 26 ms 23684 KB Output is correct
32 Correct 23 ms 23720 KB Output is correct
33 Correct 19 ms 23788 KB Output is correct
34 Correct 13 ms 23752 KB Output is correct
35 Correct 13 ms 23764 KB Output is correct
36 Correct 14 ms 23752 KB Output is correct
37 Correct 11 ms 23756 KB Output is correct
38 Correct 13 ms 23732 KB Output is correct
39 Correct 17 ms 23756 KB Output is correct
40 Correct 16 ms 23748 KB Output is correct
41 Correct 35 ms 23724 KB Output is correct
42 Correct 11 ms 23764 KB Output is correct
43 Correct 11 ms 23764 KB Output is correct
44 Correct 12 ms 23764 KB Output is correct
45 Correct 11 ms 23752 KB Output is correct
46 Correct 17 ms 23764 KB Output is correct
47 Correct 13 ms 23764 KB Output is correct
48 Correct 22 ms 23764 KB Output is correct
49 Correct 30 ms 23728 KB Output is correct
50 Correct 16 ms 23808 KB Output is correct
51 Correct 20 ms 23760 KB Output is correct
52 Correct 16 ms 23696 KB Output is correct
53 Correct 13 ms 23816 KB Output is correct
54 Correct 11 ms 23784 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 11 ms 23712 KB Output is correct
57 Correct 11 ms 23764 KB Output is correct
58 Correct 11 ms 23728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23752 KB Output is correct
2 Correct 21 ms 23760 KB Output is correct
3 Correct 18 ms 23752 KB Output is correct
4 Correct 11 ms 23748 KB Output is correct
5 Correct 11 ms 23764 KB Output is correct
6 Correct 11 ms 23748 KB Output is correct
7 Correct 74 ms 27704 KB Output is correct
8 Correct 71 ms 27680 KB Output is correct
9 Correct 88 ms 27712 KB Output is correct
10 Correct 72 ms 27724 KB Output is correct
11 Correct 71 ms 27592 KB Output is correct
12 Correct 65 ms 27708 KB Output is correct
13 Correct 74 ms 27800 KB Output is correct
14 Correct 68 ms 27708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23780 KB Output is correct
2 Correct 10 ms 23764 KB Output is correct
3 Correct 9 ms 23764 KB Output is correct
4 Correct 11 ms 23716 KB Output is correct
5 Correct 9 ms 23764 KB Output is correct
6 Correct 10 ms 23728 KB Output is correct
7 Correct 10 ms 23756 KB Output is correct
8 Correct 11 ms 23820 KB Output is correct
9 Correct 10 ms 23764 KB Output is correct
10 Correct 10 ms 23752 KB Output is correct
11 Correct 11 ms 23804 KB Output is correct
12 Correct 11 ms 23752 KB Output is correct
13 Correct 10 ms 23756 KB Output is correct
14 Correct 11 ms 23756 KB Output is correct
15 Correct 10 ms 23736 KB Output is correct
16 Correct 12 ms 23752 KB Output is correct
17 Correct 12 ms 23760 KB Output is correct
18 Correct 9 ms 23764 KB Output is correct
19 Correct 9 ms 23792 KB Output is correct
20 Correct 9 ms 23764 KB Output is correct
21 Correct 9 ms 23748 KB Output is correct
22 Correct 9 ms 23796 KB Output is correct
23 Correct 10 ms 23788 KB Output is correct
24 Correct 9 ms 23712 KB Output is correct
25 Correct 12 ms 23756 KB Output is correct
26 Correct 9 ms 23812 KB Output is correct
27 Correct 9 ms 23760 KB Output is correct
28 Correct 9 ms 23752 KB Output is correct
29 Correct 10 ms 23764 KB Output is correct
30 Correct 10 ms 23772 KB Output is correct
31 Correct 26 ms 23684 KB Output is correct
32 Correct 23 ms 23720 KB Output is correct
33 Correct 19 ms 23788 KB Output is correct
34 Correct 13 ms 23752 KB Output is correct
35 Correct 13 ms 23764 KB Output is correct
36 Correct 14 ms 23752 KB Output is correct
37 Correct 11 ms 23756 KB Output is correct
38 Correct 13 ms 23732 KB Output is correct
39 Correct 17 ms 23756 KB Output is correct
40 Correct 16 ms 23748 KB Output is correct
41 Correct 35 ms 23724 KB Output is correct
42 Correct 11 ms 23764 KB Output is correct
43 Correct 11 ms 23764 KB Output is correct
44 Correct 12 ms 23764 KB Output is correct
45 Correct 11 ms 23752 KB Output is correct
46 Correct 17 ms 23764 KB Output is correct
47 Correct 13 ms 23764 KB Output is correct
48 Correct 22 ms 23764 KB Output is correct
49 Correct 30 ms 23728 KB Output is correct
50 Correct 16 ms 23808 KB Output is correct
51 Correct 20 ms 23760 KB Output is correct
52 Correct 16 ms 23696 KB Output is correct
53 Correct 13 ms 23816 KB Output is correct
54 Correct 11 ms 23784 KB Output is correct
55 Correct 11 ms 23764 KB Output is correct
56 Correct 11 ms 23712 KB Output is correct
57 Correct 11 ms 23764 KB Output is correct
58 Correct 11 ms 23728 KB Output is correct
59 Correct 12 ms 23752 KB Output is correct
60 Correct 21 ms 23760 KB Output is correct
61 Correct 18 ms 23752 KB Output is correct
62 Correct 11 ms 23748 KB Output is correct
63 Correct 11 ms 23764 KB Output is correct
64 Correct 11 ms 23748 KB Output is correct
65 Correct 74 ms 27704 KB Output is correct
66 Correct 71 ms 27680 KB Output is correct
67 Correct 88 ms 27712 KB Output is correct
68 Correct 72 ms 27724 KB Output is correct
69 Correct 71 ms 27592 KB Output is correct
70 Correct 65 ms 27708 KB Output is correct
71 Correct 74 ms 27800 KB Output is correct
72 Correct 68 ms 27708 KB Output is correct
73 Correct 70 ms 27716 KB Output is correct
74 Correct 85 ms 27600 KB Output is correct
75 Correct 64 ms 27708 KB Output is correct
76 Correct 68 ms 27592 KB Output is correct
77 Correct 72 ms 27712 KB Output is correct
78 Correct 80 ms 27596 KB Output is correct
79 Correct 72 ms 27748 KB Output is correct
80 Correct 63 ms 27708 KB Output is correct
81 Correct 68 ms 27712 KB Output is correct
82 Correct 74 ms 27784 KB Output is correct
83 Correct 82 ms 27592 KB Output is correct
84 Correct 89 ms 27660 KB Output is correct
85 Correct 91 ms 27708 KB Output is correct
86 Correct 79 ms 27696 KB Output is correct
87 Correct 76 ms 27604 KB Output is correct
88 Correct 83 ms 27636 KB Output is correct
89 Correct 101 ms 27712 KB Output is correct
90 Correct 136 ms 27680 KB Output is correct
91 Correct 152 ms 27700 KB Output is correct
92 Correct 109 ms 27708 KB Output is correct
93 Correct 71 ms 27620 KB Output is correct
94 Correct 144 ms 27712 KB Output is correct
95 Correct 94 ms 27716 KB Output is correct
96 Correct 117 ms 27708 KB Output is correct
97 Correct 73 ms 27700 KB Output is correct
98 Correct 74 ms 27604 KB Output is correct
99 Correct 77 ms 27708 KB Output is correct
100 Correct 75 ms 27716 KB Output is correct
101 Correct 75 ms 27712 KB Output is correct
102 Correct 86 ms 27656 KB Output is correct