-
Notifications
You must be signed in to change notification settings - Fork 0
/
bits_equalizer.py
43 lines (33 loc) · 887 Bytes
/
bits_equalizer.py
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
import math
import queue
def main():
n = int(input())
for i in range(n):
s = input()
t = input()
z, o, q, oE, zE = 0, 0, 0, 0, 0
for j, c in enumerate(s):
if c == '0':
z -= 1
elif c == '1':
o -= 1
else:
q += 1
if t[j] == '0':
z += 1
else:
o += 1
if t[j] != s[j]:
if s[j] =='0':
zE += 1
elif s[j] == '1':
oE += 1
# check for impossible case
if z + o < q or o < 0:
print(f'Case {i + 1}: -1')
continue
swaps = min(oE, zE)
err = (oE - swaps) + (zE - swaps)
ans = swaps + err + q
print(f'Case {i + 1}: {int(ans)}')
main()