-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitsequalizer.cpp
More file actions
47 lines (44 loc) · 1.07 KB
/
bitsequalizer.cpp
File metadata and controls
47 lines (44 loc) · 1.07 KB
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
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define ll long long
int main() {
int c;
cin>>c;
string line;
getline(cin, line);
for(int p=1;p<=c;p++){
string s,t;
getline(cin, s);
getline(cin, t);
int ztoo=0,otoz=0,qtoz=0,qtoo=0;
for(int i=0;i<s.size();i++){
if(s[i]=='0'&&t[i]=='1'){
ztoo++;
}else if((s[i]=='1'&&t[i]=='0')){
otoz++;
}else if((s[i]=='?'&&t[i]=='0')){
qtoz++;
}else if((s[i]=='?'&&t[i]=='1')){
qtoo++;
}
}
cout<<"Case "<<p<<": ";
int moves=min(ztoo,otoz);
ztoo-=moves;
otoz-=moves;
if(otoz>0){
int swapwithq=min(otoz,qtoo);
moves+=swapwithq;
otoz-=swapwithq;
qtoz+=swapwithq;
qtoo-=swapwithq;
if(otoz>0) {
cout<<-1<<endl; continue;
}
}
moves+=ztoo;
moves+=(qtoz+qtoo);
cout<<moves<<endl;
}
}