Submission #1030538

# Submission time Handle Problem Language Result Execution time Memory
1030538 2024-07-22T06:34:41 Z 변재우(#10959) Lamps (JOI19_lamps) C++17
100 / 100
190 ms 108216 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int Nmax=1000010;
int N, ans, D1[Nmax], D2[3][Nmax], D3[3][3][Nmax];
bool A[Nmax], B[Nmax];
int X[3][2]={{0, 0}, {1, 1}, {1, 0}};
string At, Bt;

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>N>>At>>Bt;
    for(int i=1; i<=N; i++) A[i]=(At[i-1]=='1'), B[i]=(Bt[i-1]=='1');
    for(int i=0; i<=N; i++) D1[i]=Nmax;
    for(int a=0; a<3; a++) for(int i=0; i<=N; i++) D2[a][i]=Nmax;
    for(int a=0; a<3; a++) for(int b=0; b<3; b++) for(int i=0; i<=N; i++) D3[a][b][i]=Nmax;
    D1[0]=0;
    for(int i=1; i<=N; i++) {
        if(A[i]==B[i]) {
            D1[i]=min(D1[i], D1[i-1]);
            for(int a=0; a<3; a++) D1[i]=min(D1[i], D2[a][i-1]);
            for(int a=0; a<3; a++) for(int b=0; b<3; b++) D1[i]=min(D1[i], D3[a][b][i]);
        }
        for(int a=0; a<3; a++) if(X[a][A[i]]==B[i]) {
            D2[a][i]=min(D2[a][i], D1[i-1]+1);
            for(int b=0; b<3; b++) D2[a][i]=min(D2[a][i], D2[b][i-1]+(a!=b));
            for(int b=0; b<3; b++) for(int c=0; c<3; c++) D2[a][i]=min(D2[a][i], D3[b][c][i-1]+(a!=b && a!=c));
        }
        for(int a=0; a<3; a++) for(int b=0; b<3; b++) if(X[b][X[a][A[i]]]==B[i]) {
            D3[a][b][i]=min(D3[a][b][i], D1[i-1]+2);
            for(int c=0; c<3; c++) D3[a][b][i]=min(D3[a][b][i], D2[c][i-1]+1+(a!=c && b!=c));
            for(int c=0; c<3; c++) for(int d=0; d<3; d++) {
                int x=0;
                if(a==c && b==d) x=0;
                else if(a==c || a==d || b==c || b==d) x=1;
                else x=2;
                D3[a][b][i]=min(D3[a][b][i], D3[c][d][i-1]+x);
            }
        }
    }
    ans=D1[N];
    for(int a=0; a<3; a++) ans=min(ans, D2[a][N]);
    for(int a=0; a<3; a++) for(int b=0; b<3; b++) ans=min(ans, D3[a][b][N]);
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 464 KB Output is correct
23 Correct 0 ms 464 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 464 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 464 KB Output is correct
23 Correct 0 ms 464 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 464 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 792 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 720 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 159 ms 107964 KB Output is correct
8 Correct 185 ms 108192 KB Output is correct
9 Correct 158 ms 108192 KB Output is correct
10 Correct 151 ms 108212 KB Output is correct
11 Correct 149 ms 108108 KB Output is correct
12 Correct 146 ms 108104 KB Output is correct
13 Correct 146 ms 108208 KB Output is correct
14 Correct 150 ms 108216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 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 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 464 KB Output is correct
23 Correct 0 ms 464 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 464 KB Output is correct
32 Correct 1 ms 344 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 1 ms 604 KB Output is correct
40 Correct 2 ms 2652 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 1 ms 604 KB Output is correct
43 Correct 1 ms 604 KB Output is correct
44 Correct 1 ms 604 KB Output is correct
45 Correct 1 ms 604 KB Output is correct
46 Correct 2 ms 600 KB Output is correct
47 Correct 1 ms 604 KB Output is correct
48 Correct 1 ms 604 KB Output is correct
49 Correct 1 ms 604 KB Output is correct
50 Correct 1 ms 604 KB Output is correct
51 Correct 1 ms 792 KB Output is correct
52 Correct 1 ms 604 KB Output is correct
53 Correct 1 ms 604 KB Output is correct
54 Correct 1 ms 604 KB Output is correct
55 Correct 1 ms 604 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 1 ms 720 KB Output is correct
58 Correct 2 ms 724 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 1 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 344 KB Output is correct
65 Correct 159 ms 107964 KB Output is correct
66 Correct 185 ms 108192 KB Output is correct
67 Correct 158 ms 108192 KB Output is correct
68 Correct 151 ms 108212 KB Output is correct
69 Correct 149 ms 108108 KB Output is correct
70 Correct 146 ms 108104 KB Output is correct
71 Correct 146 ms 108208 KB Output is correct
72 Correct 150 ms 108216 KB Output is correct
73 Correct 149 ms 107968 KB Output is correct
74 Correct 160 ms 108116 KB Output is correct
75 Correct 167 ms 108164 KB Output is correct
76 Correct 136 ms 108000 KB Output is correct
77 Correct 135 ms 108112 KB Output is correct
78 Correct 143 ms 108188 KB Output is correct
79 Correct 152 ms 108200 KB Output is correct
80 Correct 162 ms 108116 KB Output is correct
81 Correct 139 ms 108056 KB Output is correct
82 Correct 127 ms 108212 KB Output is correct
83 Correct 149 ms 108196 KB Output is correct
84 Correct 136 ms 108188 KB Output is correct
85 Correct 141 ms 108208 KB Output is correct
86 Correct 139 ms 108192 KB Output is correct
87 Correct 142 ms 108192 KB Output is correct
88 Correct 139 ms 108192 KB Output is correct
89 Correct 145 ms 108208 KB Output is correct
90 Correct 156 ms 108188 KB Output is correct
91 Correct 142 ms 108192 KB Output is correct
92 Correct 190 ms 108192 KB Output is correct
93 Correct 146 ms 108196 KB Output is correct
94 Correct 145 ms 108112 KB Output is correct
95 Correct 146 ms 107976 KB Output is correct
96 Correct 137 ms 108000 KB Output is correct
97 Correct 154 ms 108212 KB Output is correct
98 Correct 143 ms 108100 KB Output is correct
99 Correct 144 ms 108184 KB Output is correct
100 Correct 151 ms 108192 KB Output is correct
101 Correct 154 ms 108196 KB Output is correct
102 Correct 159 ms 108096 KB Output is correct