Iam_Sandeep

Untitled

Mar 20th, 2026
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. def calcmin(seq,x,y):
  2.     def add(l,n):
  3.         l[0]+=n[0]
  4.         l[1]+=n[1]
  5.     ones, zeros = [0,0],[0,0]
  6.     oz =[0,0]
  7.     zo = [0,0]
  8.     for c in seq:
  9.         if c == '0':
  10.             add(oz,ones)
  11.             add(zeros,[1,1])
  12.         elif c == '1':
  13.             add(zo,zeros)
  14.             add(ones,[1,1])
  15.         elif c == '!':
  16.             # ! is 0
  17.             oz[0] += ones[0]
  18.             zeros[0]+=1
  19.             # ! is 1
  20.             zo[1] += zeros[1]
  21.             ones[1]+=1
  22.  
  23.     return min(zo[0]*x+oz[0]*y,zo[1]*x+oz[1]*y)
Advertisement
Add Comment
Please, Sign In to add comment