Submission #823474

# Submission time Handle Problem Language Result Execution time Memory
823474 2023-08-12T14:50:36 Z LucaIlie Lamps (JOI19_lamps) C++17
100 / 100
75 ms 33744 KB
#include <bits/stdc++.h>

using namespace std;

const int ON0 = 1;
const int ON1 = 0;
const int OFF = 2;
const int MAX_N = 1e6;
int initial[MAX_N + 1], corect[MAX_N + 1];
int dp[MAX_N + 1][3][2];

int main() {
    int n;
    string a, b;

    cin >> n >> a >> b;
    initial[0] = corect[0] = 0;
    for ( int i = 0; i < n; i++ ) {
        initial[i + 1] = a[i] - '0';
        corect[i + 1] = b[i] - '0';
    }

    for ( int i = 0; i <= n; i++ ) {
        for ( int s = 0; s < 3; s++ ) {
            for ( int b = 0; b < 2; b++ )
                dp[i][s][b] = n;
        }
    }
    dp[0][OFF][0] = 0;
    for ( int i = 1; i <= n; i++ ) {
        //OFF
        for ( int s = 0; s < 3; s++ ) {
            dp[i][OFF][initial[i]] = min( dp[i][OFF][initial[i]], dp[i - 1][s][corect[i - 1]] + (initial[i] != corect[i]) ); //era corect
            dp[i][OFF][initial[i]] = min( dp[i][OFF][initial[i]], dp[i - 1][s][corect[i - 1] ^ 1] ); //era gresit
        }

        //ON0
        for ( int s = 0; s < 3; s++ ) {
            dp[i][ON0][0] = min( dp[i][ON0][0], dp[i - 1][s][corect[i - 1]] + (s != ON0) + (corect[i] != 0) ); //era corect
            dp[i][ON0][0] = min( dp[i][ON0][0], dp[i - 1][s][corect[i - 1] ^ 1] + (s != ON0) ); //era gresit
        }

        //ON1
        for ( int s = 0; s < 3; s++ ) {
            dp[i][ON1][1] = min( dp[i][ON1][1], dp[i - 1][s][corect[i - 1]] + (s != ON1) + (corect[i] != 1) ); //era corect
            dp[i][ON1][1] = min( dp[i][ON1][1], dp[i - 1][s][corect[i - 1] ^ 1] + (s != ON1) ); //era gresit
        }
    }

    int minn = MAX_N;
    for ( int s = 0; s < 3; s++ ) {
        for ( int b = 0; b < 2; b++ )
            minn = min( minn, dp[n][s][b] );
    }

    cout << minn;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 356 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 60 ms 33592 KB Output is correct
8 Correct 61 ms 33700 KB Output is correct
9 Correct 60 ms 33644 KB Output is correct
10 Correct 58 ms 33640 KB Output is correct
11 Correct 60 ms 33700 KB Output is correct
12 Correct 59 ms 33700 KB Output is correct
13 Correct 59 ms 33696 KB Output is correct
14 Correct 64 ms 33600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 0 ms 340 KB Output is correct
37 Correct 0 ms 340 KB Output is correct
38 Correct 0 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 1 ms 340 KB Output is correct
45 Correct 1 ms 340 KB Output is correct
46 Correct 1 ms 340 KB Output is correct
47 Correct 0 ms 340 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 0 ms 340 KB Output is correct
50 Correct 1 ms 340 KB Output is correct
51 Correct 0 ms 340 KB Output is correct
52 Correct 0 ms 340 KB Output is correct
53 Correct 0 ms 340 KB Output is correct
54 Correct 0 ms 340 KB Output is correct
55 Correct 0 ms 340 KB Output is correct
56 Correct 1 ms 356 KB Output is correct
57 Correct 0 ms 340 KB Output is correct
58 Correct 0 ms 340 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 212 KB Output is correct
65 Correct 60 ms 33592 KB Output is correct
66 Correct 61 ms 33700 KB Output is correct
67 Correct 60 ms 33644 KB Output is correct
68 Correct 58 ms 33640 KB Output is correct
69 Correct 60 ms 33700 KB Output is correct
70 Correct 59 ms 33700 KB Output is correct
71 Correct 59 ms 33696 KB Output is correct
72 Correct 64 ms 33600 KB Output is correct
73 Correct 58 ms 33704 KB Output is correct
74 Correct 62 ms 33716 KB Output is correct
75 Correct 62 ms 33704 KB Output is correct
76 Correct 72 ms 33704 KB Output is correct
77 Correct 61 ms 33696 KB Output is correct
78 Correct 61 ms 33628 KB Output is correct
79 Correct 62 ms 33628 KB Output is correct
80 Correct 60 ms 33704 KB Output is correct
81 Correct 61 ms 33640 KB Output is correct
82 Correct 59 ms 33700 KB Output is correct
83 Correct 68 ms 33684 KB Output is correct
84 Correct 59 ms 33584 KB Output is correct
85 Correct 59 ms 33716 KB Output is correct
86 Correct 59 ms 33608 KB Output is correct
87 Correct 60 ms 33684 KB Output is correct
88 Correct 59 ms 33704 KB Output is correct
89 Correct 75 ms 33700 KB Output is correct
90 Correct 65 ms 33700 KB Output is correct
91 Correct 73 ms 33648 KB Output is correct
92 Correct 61 ms 33660 KB Output is correct
93 Correct 63 ms 33628 KB Output is correct
94 Correct 64 ms 33596 KB Output is correct
95 Correct 61 ms 33676 KB Output is correct
96 Correct 63 ms 33580 KB Output is correct
97 Correct 70 ms 33744 KB Output is correct
98 Correct 65 ms 33676 KB Output is correct
99 Correct 70 ms 33700 KB Output is correct
100 Correct 67 ms 33696 KB Output is correct
101 Correct 62 ms 33632 KB Output is correct
102 Correct 63 ms 33696 KB Output is correct