Submission #943315

# Submission time Handle Problem Language Result Execution time Memory
943315 2024-03-11T10:37:11 Z relex Lamps (JOI19_lamps) C++17
100 / 100
84 ms 35808 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
gp_hash_table<ll, ll, custom_hash> app;
//const int MOD = 998244353;
//const int MOD = 1e9 + 7;

constexpr ll INF = 1e9;

vector<ll> a;


ll n, m, k, q, x, y, z, w, h, T;
string s, t;
double p;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    T = 1;
    //cin >> T;
    while (T--) {    
        cin >> n;
        cin >> s >> t;

        int a[n], b[n];
        for (int i = 0; i < n; i++) {
            a[i] = s[i] - '0';
            b[i] = t[i] - '0';
        }

        int dp[n + 1][3][2] = {}; // dp[index][setNumber (2 if don't change)][toggle]. Notice that toggle always comes after number
        for (int i = 0; i <= n; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 2; k++) {
                    dp[i][j][k] = INF;
                }
            }
        }

        int changetoggle[2][2] = {}; 
        changetoggle[0][1] = 1;

        int changenumber[3][3] = {};
        changenumber[0][1] = 1; changenumber[1][0] = 1; changenumber[2][0] = 1; changenumber[2][1] = 1;

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


        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 2; k++) {
                    for (int jj = 0; jj < 3; jj++) {
                        for (int kk = 0; kk < 2; kk++) {
                            int num = a[i];
                            if (jj != 2) num = jj;
                            if (kk) num = 1 - num;
                            if (num != b[i]) continue;
                            dp[i + 1][jj][kk] = min(dp[i + 1][jj][kk], dp[i][j][k] + changenumber[j][jj] + changetoggle[k][kk]);
                        }
                    }
                }
            }
        }

        int ans = INF;
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 2; k++) {
                ans = min(ans, dp[n][j][k]);
            }
        }
        printf("%i\n", ans);

        
    }


}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 448 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 448 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 452 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 456 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 448 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 448 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 452 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 456 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 408 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 452 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 69 ms 35692 KB Output is correct
8 Correct 70 ms 35712 KB Output is correct
9 Correct 82 ms 35800 KB Output is correct
10 Correct 73 ms 35800 KB Output is correct
11 Correct 84 ms 35796 KB Output is correct
12 Correct 68 ms 35796 KB Output is correct
13 Correct 72 ms 35796 KB Output is correct
14 Correct 68 ms 35748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 448 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 448 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 452 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 456 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 1 ms 344 KB Output is correct
39 Correct 1 ms 348 KB Output is correct
40 Correct 1 ms 348 KB Output is correct
41 Correct 1 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 1 ms 344 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 1 ms 348 KB Output is correct
47 Correct 1 ms 344 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 1 ms 600 KB Output is correct
54 Correct 1 ms 348 KB Output is correct
55 Correct 1 ms 408 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 1 ms 604 KB Output is correct
58 Correct 1 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 0 ms 452 KB Output is correct
64 Correct 0 ms 344 KB Output is correct
65 Correct 69 ms 35692 KB Output is correct
66 Correct 70 ms 35712 KB Output is correct
67 Correct 82 ms 35800 KB Output is correct
68 Correct 73 ms 35800 KB Output is correct
69 Correct 84 ms 35796 KB Output is correct
70 Correct 68 ms 35796 KB Output is correct
71 Correct 72 ms 35796 KB Output is correct
72 Correct 68 ms 35748 KB Output is correct
73 Correct 69 ms 35748 KB Output is correct
74 Correct 73 ms 35804 KB Output is correct
75 Correct 68 ms 35804 KB Output is correct
76 Correct 69 ms 35804 KB Output is correct
77 Correct 71 ms 35584 KB Output is correct
78 Correct 69 ms 35576 KB Output is correct
79 Correct 72 ms 35768 KB Output is correct
80 Correct 77 ms 35804 KB Output is correct
81 Correct 71 ms 35760 KB Output is correct
82 Correct 71 ms 35808 KB Output is correct
83 Correct 73 ms 35800 KB Output is correct
84 Correct 74 ms 35800 KB Output is correct
85 Correct 72 ms 35636 KB Output is correct
86 Correct 74 ms 35752 KB Output is correct
87 Correct 74 ms 35752 KB Output is correct
88 Correct 74 ms 35748 KB Output is correct
89 Correct 74 ms 35748 KB Output is correct
90 Correct 76 ms 35748 KB Output is correct
91 Correct 77 ms 35752 KB Output is correct
92 Correct 80 ms 35628 KB Output is correct
93 Correct 81 ms 35808 KB Output is correct
94 Correct 80 ms 35804 KB Output is correct
95 Correct 79 ms 35760 KB Output is correct
96 Correct 79 ms 35800 KB Output is correct
97 Correct 84 ms 35800 KB Output is correct
98 Correct 84 ms 35800 KB Output is correct
99 Correct 80 ms 35800 KB Output is correct
100 Correct 81 ms 35760 KB Output is correct
101 Correct 80 ms 35796 KB Output is correct
102 Correct 79 ms 35772 KB Output is correct