Advertisement
FSan

Second python 2 complex code

Jun 6th, 2024 (edited)
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. MOD = 10**9 + 7
  2.  
  3. def getMinErrors(errorString, x, y):
  4.     n = len(errorString)
  5.     total_01 = 0
  6.     total_10 = 0
  7.     count_0 = 0
  8.     count_1 = 0
  9.    
  10.     for char in errorString:
  11.         if char == '0':
  12.             total_10 += count_1
  13.             count_0 += 1
  14.         elif char == '1':
  15.             total_01 += count_0
  16.             count_1 += 1
  17.    
  18.     min_errors_0 = total_01 * x
  19.     min_errors_1 = total_10 * y
  20.    
  21.     for char in errorString:
  22.         if char == '!':
  23.             count_0 += 1
  24.             min_errors_0 += total_10 * y
  25.             min_errors_0 %= MOD
  26.             count_1 += 1
  27.             min_errors_1 += total_01 * x
  28.             min_errors_1 %= MOD
  29.    
  30.     return min(min_errors_0, min_errors_1)
  31.  
  32. # Ejemplo de uso
  33. errorString = "1011!"
  34. x = 2
  35. y = 3
  36. print(getMinErrors(errorString, x, y))  # Salida esperada: 9
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement