-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCF_1381A2.py
46 lines (45 loc) · 1.12 KB
/
CF_1381A2.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
44
45
46
import sys
r=sys.stdin.readline
def revAndnot(bit,idx):
tmp=""
for i in range(idx):
tmp+='1' if bit[i]=='0' else '0'
return tmp[::-1]+bit[idx:]
for _ in range(int(r())):
n=int(r()) #length of binary
a=r().strip()
b=r().strip()
ans=[]
""" 3n operation method
for i in range(n):
if a[i]!=b[i]:
if i>0:
ans.append(str(i+1))
ans.append('1')
if i>0:
ans.append(str(i+1))
"""
"""2n operation method
for i in range(n-1,-1,-1):
if b[i]==a[i]:
continue
elif a[0]==b[i]:#2op
a=revAndnot(a,1)
a=revAndnot(a,i+1)
ans.append(str(1))
ans.append(str(i+1))
else:
a=revAndnot(a,i+1)
ans.append(str(i+1))
"""
flip=False
idx=0
for i in range(n-1,-1,-1):
if flip^(a[idx]==b[i]):
ans.append(str(1))
ans.append(str(i+1))
if flip: idx-=i
else: idx+=i
flip^=True
print(len(ans),end=" ")
print(' '.join(ans))