Submission #422504

# Submission time Handle Problem Language Result Execution time Memory
422504 2021-06-10T07:39:46 Z qwerasdfzxcl Lamps (JOI19_lamps) C++14
100 / 100
136 ms 71036 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
string x, y;
int dp0[1001000], dp1[1001000][3], dp2[1001000][3][3], ans[1001000], dp2mn[1001000][3];

void getmn(int x){
    for (int i=0;i<3;i++){
        ans[x] = min(ans[x], dp1[x][i]);
        for (int j=0;j<3;j++){
            dp2mn[x][i] = min(dp2mn[x][i], dp2[x][i][j]);
            dp2mn[x][j] = min(dp2mn[x][j], dp2[x][i][j]);
            ans[x] = min(ans[x], dp2[x][i][j]);
        }
    }
    ans[x] = min(ans[x], dp0[x]);
}

int main(){
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n >> x >> y;
    for (int i=0;i<n;i++){
        dp0[i] = 1e9;
        ans[i] = 1e9;
        fill(dp1[i], dp1[i]+3, 1e9);
        fill(dp2mn[i], dp2mn[i]+3, 1e9);
        for (int j=0;j<3;j++) fill(dp2[i][j], dp2[i][j]+3, 1e9);
    }
    if (x[0]==y[0]) dp0[0] = 0, dp2[0][2][2] = 2;
    else dp1[0][2] = 1, dp2[0][0][2] = 2, dp2[0][1][2] = 2;
    dp1[0][y[0]-'0'] = 1;
    for (int j=0;j<3;j++) dp2[0][j][y[0]-'0'] = 2;
    dp2[0][(y[0]-'0')^1][2] = 2;
    getmn(0);

    for (int i=1;i<n;i++){
        if (x[i]==y[i]) dp0[i] = ans[i-1];
        else dp1[i][2] = min(ans[i-1]+1, min(dp1[i-1][2], dp2mn[i-1][2]));
        dp1[i][y[i]-'0'] = min(ans[i-1]+1, min(dp1[i-1][y[i]-'0'], dp2mn[i-1][y[i]-'0']));

        for (int j=0;j<3;j++){
            int val1 = min(min(dp1[i-1][j], dp1[i-1][y[i]-'0']), min(dp2mn[i-1][j], dp2mn[i-1][y[i]-'0']));
            dp2[i][j][y[i]-'0'] = min(ans[i-1]+2, min(val1+1, dp2[i-1][j][y[i]-'0']));
        }
        int val = min(min(dp1[i-1][2], dp1[i-1][(y[i]-'0')^1]), min(dp2mn[i-1][2], dp2mn[i-1][(y[i]-'0')^1]));
        dp2[i][(y[i]-'0')^1][2] = min(ans[i-1]+2, min(val+1, dp2[i-1][(y[i]-'0')^1][2]));

        if (x[i]==y[i]){
            int val2 = min(dp1[i-1][2], dp2mn[i-1][2]);
            dp2[i][2][2] = min(ans[i-1]+2, min(val2+1, dp2[i-1][2][2]));
        }

        getmn(i);
    }
/*
    for (int i=0;i<n;i++) printf("%d ", dp0[i]);
    printf("\n\n");
    for (int j=0;j<3;j++){
        for (int i=0;i<n;i++) printf("%d ", dp1[i][j]);
        printf("\n");
    }
    printf("\n");
    for (int j=0;j<3;j++){
        for (int k=0;k<3;k++){
            for (int i=0;i<n;i++) printf("%d ", dp2[i][j][k]);
            printf("\n");
        }
    }
    printf("\n");
    for (int i=0;i<n;i++) printf("%d ", ans[i]);
    printf("\n\n");
*/
    cout << ans[n-1];
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 448 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 472 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 444 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 1 ms 444 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 111 ms 70916 KB Output is correct
8 Correct 109 ms 70828 KB Output is correct
9 Correct 111 ms 71036 KB Output is correct
10 Correct 112 ms 70916 KB Output is correct
11 Correct 113 ms 70900 KB Output is correct
12 Correct 113 ms 70848 KB Output is correct
13 Correct 121 ms 70920 KB Output is correct
14 Correct 122 ms 70916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 316 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 316 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 320 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 316 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 460 KB Output is correct
36 Correct 1 ms 460 KB Output is correct
37 Correct 1 ms 460 KB Output is correct
38 Correct 1 ms 448 KB Output is correct
39 Correct 1 ms 460 KB Output is correct
40 Correct 1 ms 460 KB Output is correct
41 Correct 1 ms 460 KB Output is correct
42 Correct 1 ms 460 KB Output is correct
43 Correct 1 ms 460 KB Output is correct
44 Correct 1 ms 460 KB Output is correct
45 Correct 1 ms 472 KB Output is correct
46 Correct 1 ms 460 KB Output is correct
47 Correct 1 ms 460 KB Output is correct
48 Correct 1 ms 460 KB Output is correct
49 Correct 1 ms 460 KB Output is correct
50 Correct 1 ms 460 KB Output is correct
51 Correct 1 ms 460 KB Output is correct
52 Correct 1 ms 460 KB Output is correct
53 Correct 1 ms 460 KB Output is correct
54 Correct 1 ms 444 KB Output is correct
55 Correct 1 ms 460 KB Output is correct
56 Correct 1 ms 460 KB Output is correct
57 Correct 1 ms 444 KB Output is correct
58 Correct 1 ms 460 KB Output is correct
59 Correct 1 ms 332 KB Output is correct
60 Correct 1 ms 332 KB Output is correct
61 Correct 1 ms 332 KB Output is correct
62 Correct 0 ms 332 KB Output is correct
63 Correct 1 ms 332 KB Output is correct
64 Correct 1 ms 332 KB Output is correct
65 Correct 111 ms 70916 KB Output is correct
66 Correct 109 ms 70828 KB Output is correct
67 Correct 111 ms 71036 KB Output is correct
68 Correct 112 ms 70916 KB Output is correct
69 Correct 113 ms 70900 KB Output is correct
70 Correct 113 ms 70848 KB Output is correct
71 Correct 121 ms 70920 KB Output is correct
72 Correct 122 ms 70916 KB Output is correct
73 Correct 132 ms 70928 KB Output is correct
74 Correct 114 ms 70920 KB Output is correct
75 Correct 113 ms 70856 KB Output is correct
76 Correct 116 ms 70976 KB Output is correct
77 Correct 125 ms 70812 KB Output is correct
78 Correct 110 ms 70864 KB Output is correct
79 Correct 134 ms 70812 KB Output is correct
80 Correct 111 ms 70924 KB Output is correct
81 Correct 135 ms 70916 KB Output is correct
82 Correct 115 ms 70920 KB Output is correct
83 Correct 119 ms 70916 KB Output is correct
84 Correct 118 ms 70924 KB Output is correct
85 Correct 118 ms 70884 KB Output is correct
86 Correct 117 ms 70800 KB Output is correct
87 Correct 119 ms 70908 KB Output is correct
88 Correct 120 ms 70920 KB Output is correct
89 Correct 119 ms 70804 KB Output is correct
90 Correct 136 ms 70832 KB Output is correct
91 Correct 133 ms 70888 KB Output is correct
92 Correct 134 ms 70916 KB Output is correct
93 Correct 128 ms 70920 KB Output is correct
94 Correct 129 ms 70904 KB Output is correct
95 Correct 124 ms 70804 KB Output is correct
96 Correct 126 ms 70936 KB Output is correct
97 Correct 127 ms 70940 KB Output is correct
98 Correct 125 ms 70980 KB Output is correct
99 Correct 126 ms 70804 KB Output is correct
100 Correct 128 ms 70920 KB Output is correct
101 Correct 126 ms 70916 KB Output is correct
102 Correct 128 ms 70916 KB Output is correct