//####################
//Lamps
//####################
#include <algorithm>
#include<bits/stdc++.h>
#include <utility>
using namespace std;
string A,B;
const int inf = 2*1e6;
#define pb push_back
#define SET0 1
#define SET1 2
#define FLIP 3
void dbg(vector<int> d){
for(int i:d){
if(i==SET0)cout<<"set0 ;";
if(i==SET1)cout<<"set1 ;";
if(i==FLIP)cout<<"flip ;";
}
cout<<endl;
}
bool apply(bool r,int m){
if(m==SET0)return 0;
if(m==SET1)return 1;
if(m==FLIP)return r^1;
return r;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie();
int n; cin >> n;
cin >> A >> B;
int dp[n+1][4][4];
for(int a=0;a<=3;a++)for(int b=0;b<=3;b++)dp[n][a][b]=0;
vector<pair<int,int>> t;
for(int a=0;a<=3;a++)for(int b=0;b<=3;b++)t.pb(make_pair(a,b));
for(int pos = n-1;pos>=0;pos--){
for(int i1 = 0 ; i1<= 3;i1++)
for(int i2 = 0 ; i2 <= 3;i2++){
dp[pos][i1][i2] = 2*n+1;
for(auto &p:t){
bool r = A[pos]-'0';
r = apply(r,p.first);
r = apply(r,p.second);
if(r!=(bool)(B[pos]-'0'))continue;
int c=2;
if(i1==p.second && p.first==0 && i2==0){
c=0;
}else{
if(i1==p.first || p.first==0)c--;
if(i2==p.second|| p.second==0)c--;
}
dp[pos][i1][i2] = min(dp[pos][i1][i2],c+dp[pos+1][p.first][p.second]);
}
}
}
cout<<dp[0][0][0]<<endl;
return 0;
};
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
408 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
408 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
348 KB |
Output is correct |
40 |
Correct |
3 ms |
576 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
580 KB |
Output is correct |
47 |
Correct |
2 ms |
348 KB |
Output is correct |
48 |
Correct |
2 ms |
348 KB |
Output is correct |
49 |
Correct |
2 ms |
348 KB |
Output is correct |
50 |
Correct |
2 ms |
348 KB |
Output is correct |
51 |
Correct |
2 ms |
344 KB |
Output is correct |
52 |
Correct |
2 ms |
348 KB |
Output is correct |
53 |
Correct |
2 ms |
348 KB |
Output is correct |
54 |
Correct |
2 ms |
348 KB |
Output is correct |
55 |
Correct |
2 ms |
348 KB |
Output is correct |
56 |
Correct |
2 ms |
348 KB |
Output is correct |
57 |
Correct |
2 ms |
348 KB |
Output is correct |
58 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
424 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
753 ms |
65152 KB |
Output is correct |
8 |
Correct |
886 ms |
64928 KB |
Output is correct |
9 |
Correct |
945 ms |
65156 KB |
Output is correct |
10 |
Correct |
874 ms |
65152 KB |
Output is correct |
11 |
Correct |
878 ms |
64928 KB |
Output is correct |
12 |
Correct |
821 ms |
65188 KB |
Output is correct |
13 |
Correct |
812 ms |
65156 KB |
Output is correct |
14 |
Correct |
866 ms |
64944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 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 |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
408 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
452 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 |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
360 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
596 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 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 |
0 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 |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
2 ms |
348 KB |
Output is correct |
36 |
Correct |
2 ms |
348 KB |
Output is correct |
37 |
Correct |
2 ms |
348 KB |
Output is correct |
38 |
Correct |
2 ms |
348 KB |
Output is correct |
39 |
Correct |
2 ms |
348 KB |
Output is correct |
40 |
Correct |
3 ms |
576 KB |
Output is correct |
41 |
Correct |
2 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
348 KB |
Output is correct |
43 |
Correct |
2 ms |
348 KB |
Output is correct |
44 |
Correct |
2 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
348 KB |
Output is correct |
46 |
Correct |
2 ms |
580 KB |
Output is correct |
47 |
Correct |
2 ms |
348 KB |
Output is correct |
48 |
Correct |
2 ms |
348 KB |
Output is correct |
49 |
Correct |
2 ms |
348 KB |
Output is correct |
50 |
Correct |
2 ms |
348 KB |
Output is correct |
51 |
Correct |
2 ms |
344 KB |
Output is correct |
52 |
Correct |
2 ms |
348 KB |
Output is correct |
53 |
Correct |
2 ms |
348 KB |
Output is correct |
54 |
Correct |
2 ms |
348 KB |
Output is correct |
55 |
Correct |
2 ms |
348 KB |
Output is correct |
56 |
Correct |
2 ms |
348 KB |
Output is correct |
57 |
Correct |
2 ms |
348 KB |
Output is correct |
58 |
Correct |
2 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
0 ms |
424 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 |
348 KB |
Output is correct |
64 |
Correct |
0 ms |
348 KB |
Output is correct |
65 |
Correct |
753 ms |
65152 KB |
Output is correct |
66 |
Correct |
886 ms |
64928 KB |
Output is correct |
67 |
Correct |
945 ms |
65156 KB |
Output is correct |
68 |
Correct |
874 ms |
65152 KB |
Output is correct |
69 |
Correct |
878 ms |
64928 KB |
Output is correct |
70 |
Correct |
821 ms |
65188 KB |
Output is correct |
71 |
Correct |
812 ms |
65156 KB |
Output is correct |
72 |
Correct |
866 ms |
64944 KB |
Output is correct |
73 |
Correct |
782 ms |
65152 KB |
Output is correct |
74 |
Correct |
845 ms |
65152 KB |
Output is correct |
75 |
Correct |
856 ms |
65148 KB |
Output is correct |
76 |
Correct |
820 ms |
65156 KB |
Output is correct |
77 |
Correct |
958 ms |
65156 KB |
Output is correct |
78 |
Correct |
865 ms |
65156 KB |
Output is correct |
79 |
Correct |
809 ms |
64928 KB |
Output is correct |
80 |
Correct |
921 ms |
65152 KB |
Output is correct |
81 |
Correct |
857 ms |
65156 KB |
Output is correct |
82 |
Correct |
842 ms |
64936 KB |
Output is correct |
83 |
Correct |
814 ms |
64940 KB |
Output is correct |
84 |
Correct |
818 ms |
64940 KB |
Output is correct |
85 |
Correct |
872 ms |
64928 KB |
Output is correct |
86 |
Correct |
881 ms |
64928 KB |
Output is correct |
87 |
Correct |
828 ms |
64936 KB |
Output is correct |
88 |
Correct |
841 ms |
64924 KB |
Output is correct |
89 |
Correct |
828 ms |
65148 KB |
Output is correct |
90 |
Correct |
851 ms |
64936 KB |
Output is correct |
91 |
Correct |
907 ms |
64924 KB |
Output is correct |
92 |
Correct |
902 ms |
64996 KB |
Output is correct |
93 |
Correct |
907 ms |
65156 KB |
Output is correct |
94 |
Correct |
914 ms |
67088 KB |
Output is correct |
95 |
Correct |
946 ms |
67112 KB |
Output is correct |
96 |
Correct |
888 ms |
66968 KB |
Output is correct |
97 |
Correct |
881 ms |
66976 KB |
Output is correct |
98 |
Correct |
913 ms |
67232 KB |
Output is correct |
99 |
Correct |
926 ms |
67120 KB |
Output is correct |
100 |
Correct |
891 ms |
67116 KB |
Output is correct |
101 |
Correct |
902 ms |
67108 KB |
Output is correct |
102 |
Correct |
906 ms |
66984 KB |
Output is correct |