Submission #589261

# Submission time Handle Problem Language Result Execution time Memory
589261 2022-07-04T11:09:25 Z SlavicG Lamps (JOI19_lamps) C++17
6 / 100
9 ms 6388 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 = 1e2 + 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 1 ms 384 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 224 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 224 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Runtime error 1 ms 452 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Runtime error 9 ms 6388 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 324 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 224 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Runtime error 1 ms 452 KB Execution killed with signal 11
36 Halted 0 ms 0 KB -