Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. f = open('input.txt', 'r')
  2. line = f.readlines()[1]
  3. f.close()
  4.  
  5. n, k = -1, 0
  6. c = 1
  7. count = 0
  8.  
  9. for i in range(len(line) - 1, -1, -1):
  10.  
  11.     n += 1
  12.     if line[i] == '1':
  13.         k += 1
  14.  
  15.     if n < k:
  16.         continue
  17.  
  18.     if (line[i] == '1') and (k > 0):
  19.         c = c * n // k
  20.         count += c
  21.     elif n > k:
  22.         c = c * n // (n - k)
  23.  
  24. f = open('output.txt', 'w')
  25. f.write(bin(count)[2:])
  26. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement