Submission #589262

# Submission time Handle Problem Language Result Execution time Memory
589262 2022-07-04T11:09:49 Z SlavicG Lamps (JOI19_lamps) C++17
100 / 100
835 ms 130704 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

#define int long long
const int inf = 1e16;
const int N = 1e6 + 10;
ll dp[N][2][2][2][2];
void solve() {  
    int n; string a, b; cin >> n >> a >> b;
    forn(I, N) forn(A, 2) forn(B, 2) forn(C, 2) forn(D, 2) dp[I][A][B][C][D] = inf;

    dp[0][0][0][0][0] = 0;

    a = "?" + a;
    b = "?" + b;
    for(int i = 1; i <= n; ++i) {
        for(int prev_set_0: {0, 1}) {
            for(int prev_set_1: {0, 1}) {
                if(prev_set_0 && prev_set_1) continue;
                for(int prev_set_xor_before: {0, 1}) {
                    for(int prev_set_xor_after: {0, 1}) {
                        if(prev_set_xor_after && prev_set_xor_before) continue;
                        for(int set_0: {0, 1}) {
                            for(int set_1: {0, 1}) {
                                if(set_0 && set_1) continue;
                                for(int set_xor_before: {0, 1}) {
                                    for(int set_xor_after: {0, 1}) {
                                        if(set_xor_after && prev_set_xor_before) continue;
                                            int newmoves = 0;
                                            if(set_0 && !prev_set_0) ++newmoves;
                                            if(set_1 && !prev_set_1) ++newmoves;
                                            if(set_xor_before && !prev_set_xor_before) ++newmoves;
                                            if(set_xor_after && !prev_set_xor_after) ++newmoves;
                                            int x = (a[i] - '0');
                                            if(set_xor_before) x ^= 1;
                                            if(set_0) x = 0;
                                            if(set_1) x = 1;
                                            if(set_xor_after) x ^= 1;
                                            if(x != b[i] - '0') continue;
                                            dp[i][set_0][set_1][set_xor_before][set_xor_after] = 
                                            min(dp[i][set_0][set_1][set_xor_before][set_xor_after], 
                                            dp[i - 1][prev_set_0][prev_set_1][prev_set_xor_before][prev_set_xor_after] + newmoves);
                                        }
                                    }
                                }
                            }
                        }
                }
            }
        }
    }
    int ans = inf;
    for(int A: {0, 1}) for(int B: {0, 1}) for(int C: {0, 1}) for(int D: {0, 1}) ans = min(ans, dp[n][A][B][C][D]);
    cout << ans << "\n";
}   
     
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 49 ms 125516 KB Output is correct
2 Correct 51 ms 125444 KB Output is correct
3 Correct 47 ms 125548 KB Output is correct
4 Correct 48 ms 125528 KB Output is correct
5 Correct 55 ms 125516 KB Output is correct
6 Correct 53 ms 125492 KB Output is correct
7 Correct 49 ms 125476 KB Output is correct
8 Correct 49 ms 125476 KB Output is correct
9 Correct 49 ms 125504 KB Output is correct
10 Correct 55 ms 125516 KB Output is correct
11 Correct 49 ms 125472 KB Output is correct
12 Correct 53 ms 125520 KB Output is correct
13 Correct 53 ms 125512 KB Output is correct
14 Correct 51 ms 125516 KB Output is correct
15 Correct 50 ms 125428 KB Output is correct
16 Correct 51 ms 125468 KB Output is correct
17 Correct 51 ms 125528 KB Output is correct
18 Correct 51 ms 125552 KB Output is correct
19 Correct 51 ms 125516 KB Output is correct
20 Correct 51 ms 125516 KB Output is correct
21 Correct 49 ms 125492 KB Output is correct
22 Correct 50 ms 125448 KB Output is correct
23 Correct 54 ms 125452 KB Output is correct
24 Correct 50 ms 125524 KB Output is correct
25 Correct 49 ms 125540 KB Output is correct
26 Correct 49 ms 125456 KB Output is correct
27 Correct 50 ms 125512 KB Output is correct
28 Correct 50 ms 125480 KB Output is correct
29 Correct 49 ms 125436 KB Output is correct
30 Correct 48 ms 125516 KB Output is correct
31 Correct 57 ms 125516 KB Output is correct
32 Correct 52 ms 125496 KB Output is correct
33 Correct 49 ms 125516 KB Output is correct
34 Correct 57 ms 125444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 125516 KB Output is correct
2 Correct 51 ms 125444 KB Output is correct
3 Correct 47 ms 125548 KB Output is correct
4 Correct 48 ms 125528 KB Output is correct
5 Correct 55 ms 125516 KB Output is correct
6 Correct 53 ms 125492 KB Output is correct
7 Correct 49 ms 125476 KB Output is correct
8 Correct 49 ms 125476 KB Output is correct
9 Correct 49 ms 125504 KB Output is correct
10 Correct 55 ms 125516 KB Output is correct
11 Correct 49 ms 125472 KB Output is correct
12 Correct 53 ms 125520 KB Output is correct
13 Correct 53 ms 125512 KB Output is correct
14 Correct 51 ms 125516 KB Output is correct
15 Correct 50 ms 125428 KB Output is correct
16 Correct 51 ms 125468 KB Output is correct
17 Correct 51 ms 125528 KB Output is correct
18 Correct 51 ms 125552 KB Output is correct
19 Correct 51 ms 125516 KB Output is correct
20 Correct 51 ms 125516 KB Output is correct
21 Correct 49 ms 125492 KB Output is correct
22 Correct 50 ms 125448 KB Output is correct
23 Correct 54 ms 125452 KB Output is correct
24 Correct 50 ms 125524 KB Output is correct
25 Correct 49 ms 125540 KB Output is correct
26 Correct 49 ms 125456 KB Output is correct
27 Correct 50 ms 125512 KB Output is correct
28 Correct 50 ms 125480 KB Output is correct
29 Correct 49 ms 125436 KB Output is correct
30 Correct 48 ms 125516 KB Output is correct
31 Correct 57 ms 125516 KB Output is correct
32 Correct 52 ms 125496 KB Output is correct
33 Correct 49 ms 125516 KB Output is correct
34 Correct 57 ms 125444 KB Output is correct
35 Correct 51 ms 125516 KB Output is correct
36 Correct 50 ms 125500 KB Output is correct
37 Correct 54 ms 125528 KB Output is correct
38 Correct 50 ms 125500 KB Output is correct
39 Correct 51 ms 125532 KB Output is correct
40 Correct 50 ms 125516 KB Output is correct
41 Correct 50 ms 125500 KB Output is correct
42 Correct 51 ms 125432 KB Output is correct
43 Correct 50 ms 125560 KB Output is correct
44 Correct 58 ms 125540 KB Output is correct
45 Correct 51 ms 125520 KB Output is correct
46 Correct 50 ms 125532 KB Output is correct
47 Correct 50 ms 125488 KB Output is correct
48 Correct 50 ms 125516 KB Output is correct
49 Correct 53 ms 125516 KB Output is correct
50 Correct 53 ms 125496 KB Output is correct
51 Correct 51 ms 125448 KB Output is correct
52 Correct 51 ms 125440 KB Output is correct
53 Correct 50 ms 125548 KB Output is correct
54 Correct 54 ms 125528 KB Output is correct
55 Correct 55 ms 125460 KB Output is correct
56 Correct 53 ms 125560 KB Output is correct
57 Correct 54 ms 125552 KB Output is correct
58 Correct 51 ms 125460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 125496 KB Output is correct
2 Correct 49 ms 125528 KB Output is correct
3 Correct 57 ms 125544 KB Output is correct
4 Correct 59 ms 125488 KB Output is correct
5 Correct 53 ms 125516 KB Output is correct
6 Correct 49 ms 125428 KB Output is correct
7 Correct 721 ms 128624 KB Output is correct
8 Correct 732 ms 130508 KB Output is correct
9 Correct 717 ms 130544 KB Output is correct
10 Correct 717 ms 130480 KB Output is correct
11 Correct 717 ms 130584 KB Output is correct
12 Correct 721 ms 130588 KB Output is correct
13 Correct 713 ms 130460 KB Output is correct
14 Correct 729 ms 130588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 125516 KB Output is correct
2 Correct 51 ms 125444 KB Output is correct
3 Correct 47 ms 125548 KB Output is correct
4 Correct 48 ms 125528 KB Output is correct
5 Correct 55 ms 125516 KB Output is correct
6 Correct 53 ms 125492 KB Output is correct
7 Correct 49 ms 125476 KB Output is correct
8 Correct 49 ms 125476 KB Output is correct
9 Correct 49 ms 125504 KB Output is correct
10 Correct 55 ms 125516 KB Output is correct
11 Correct 49 ms 125472 KB Output is correct
12 Correct 53 ms 125520 KB Output is correct
13 Correct 53 ms 125512 KB Output is correct
14 Correct 51 ms 125516 KB Output is correct
15 Correct 50 ms 125428 KB Output is correct
16 Correct 51 ms 125468 KB Output is correct
17 Correct 51 ms 125528 KB Output is correct
18 Correct 51 ms 125552 KB Output is correct
19 Correct 51 ms 125516 KB Output is correct
20 Correct 51 ms 125516 KB Output is correct
21 Correct 49 ms 125492 KB Output is correct
22 Correct 50 ms 125448 KB Output is correct
23 Correct 54 ms 125452 KB Output is correct
24 Correct 50 ms 125524 KB Output is correct
25 Correct 49 ms 125540 KB Output is correct
26 Correct 49 ms 125456 KB Output is correct
27 Correct 50 ms 125512 KB Output is correct
28 Correct 50 ms 125480 KB Output is correct
29 Correct 49 ms 125436 KB Output is correct
30 Correct 48 ms 125516 KB Output is correct
31 Correct 57 ms 125516 KB Output is correct
32 Correct 52 ms 125496 KB Output is correct
33 Correct 49 ms 125516 KB Output is correct
34 Correct 57 ms 125444 KB Output is correct
35 Correct 51 ms 125516 KB Output is correct
36 Correct 50 ms 125500 KB Output is correct
37 Correct 54 ms 125528 KB Output is correct
38 Correct 50 ms 125500 KB Output is correct
39 Correct 51 ms 125532 KB Output is correct
40 Correct 50 ms 125516 KB Output is correct
41 Correct 50 ms 125500 KB Output is correct
42 Correct 51 ms 125432 KB Output is correct
43 Correct 50 ms 125560 KB Output is correct
44 Correct 58 ms 125540 KB Output is correct
45 Correct 51 ms 125520 KB Output is correct
46 Correct 50 ms 125532 KB Output is correct
47 Correct 50 ms 125488 KB Output is correct
48 Correct 50 ms 125516 KB Output is correct
49 Correct 53 ms 125516 KB Output is correct
50 Correct 53 ms 125496 KB Output is correct
51 Correct 51 ms 125448 KB Output is correct
52 Correct 51 ms 125440 KB Output is correct
53 Correct 50 ms 125548 KB Output is correct
54 Correct 54 ms 125528 KB Output is correct
55 Correct 55 ms 125460 KB Output is correct
56 Correct 53 ms 125560 KB Output is correct
57 Correct 54 ms 125552 KB Output is correct
58 Correct 51 ms 125460 KB Output is correct
59 Correct 49 ms 125496 KB Output is correct
60 Correct 49 ms 125528 KB Output is correct
61 Correct 57 ms 125544 KB Output is correct
62 Correct 59 ms 125488 KB Output is correct
63 Correct 53 ms 125516 KB Output is correct
64 Correct 49 ms 125428 KB Output is correct
65 Correct 721 ms 128624 KB Output is correct
66 Correct 732 ms 130508 KB Output is correct
67 Correct 717 ms 130544 KB Output is correct
68 Correct 717 ms 130480 KB Output is correct
69 Correct 717 ms 130584 KB Output is correct
70 Correct 721 ms 130588 KB Output is correct
71 Correct 713 ms 130460 KB Output is correct
72 Correct 729 ms 130588 KB Output is correct
73 Correct 747 ms 130500 KB Output is correct
74 Correct 827 ms 130516 KB Output is correct
75 Correct 734 ms 130580 KB Output is correct
76 Correct 771 ms 130516 KB Output is correct
77 Correct 712 ms 130520 KB Output is correct
78 Correct 717 ms 130512 KB Output is correct
79 Correct 784 ms 130468 KB Output is correct
80 Correct 731 ms 130464 KB Output is correct
81 Correct 708 ms 130464 KB Output is correct
82 Correct 710 ms 130556 KB Output is correct
83 Correct 740 ms 130456 KB Output is correct
84 Correct 783 ms 130584 KB Output is correct
85 Correct 731 ms 130588 KB Output is correct
86 Correct 741 ms 130484 KB Output is correct
87 Correct 835 ms 130580 KB Output is correct
88 Correct 755 ms 130512 KB Output is correct
89 Correct 749 ms 130588 KB Output is correct
90 Correct 738 ms 130556 KB Output is correct
91 Correct 755 ms 130576 KB Output is correct
92 Correct 763 ms 130588 KB Output is correct
93 Correct 759 ms 130460 KB Output is correct
94 Correct 748 ms 130556 KB Output is correct
95 Correct 766 ms 130524 KB Output is correct
96 Correct 755 ms 130600 KB Output is correct
97 Correct 752 ms 130500 KB Output is correct
98 Correct 742 ms 130588 KB Output is correct
99 Correct 748 ms 130460 KB Output is correct
100 Correct 754 ms 130704 KB Output is correct
101 Correct 776 ms 130580 KB Output is correct
102 Correct 755 ms 130588 KB Output is correct