Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def calcmin(seq,x,y):
- def add(l,n):
- l[0]+=n[0]
- l[1]+=n[1]
- ones, zeros = [0,0],[0,0]
- oz =[0,0]
- zo = [0,0]
- for c in seq:
- if c == '0':
- add(oz,ones)
- add(zeros,[1,1])
- elif c == '1':
- add(zo,zeros)
- add(ones,[1,1])
- elif c == '!':
- # ! is 0
- oz[0] += ones[0]
- zeros[0]+=1
- # ! is 1
- zo[1] += zeros[1]
- ones[1]+=1
- return min(zo[0]*x+oz[0]*y,zo[1]*x+oz[1]*y)
Advertisement
Add Comment
Please, Sign In to add comment