-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMax-Mex Cut_CF.cpp
More file actions
42 lines (41 loc) · 956 Bytes
/
Max-Mex Cut_CF.cpp
File metadata and controls
42 lines (41 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
int check(char ch1,char ch2){
if(ch1=='0' && ch2=='0')
return 1;
else if((ch1=='0' && ch2=='1')||(ch1=='1' && ch2=='0'))
return 2;
else if((ch1=='0' && ch2=='2')||(ch1=='2' && ch2=='0'))
return 1;
return 0;
}
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
string s1,s2;
cin>>s1>>s2;
int res=0;
int previous=0;
for(int i=0;i<n;i++){
if((s1[i]=='1' && s2[i]=='1') && (s1[i-1]=='0' && s2[i-1]=='0') && i!=0 && previous>=0){
res+=2;
res=res-previous;
previous=-1;
}
else if((s1[i]=='0' && s2[i]=='0') && (s1[i-1]=='1' && s2[i-1]=='1') && i!=0 && previous>=0){
res+=2;
res=res-previous;
previous=-1;
}
else{
previous=check(s1[i],s2[i]);
res+=previous;
}
}
cout<<res<<endl;
}
return 0;
}