Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MOD = 10**9 + 7
- def getMinErrors(errorString, x, y):
- n = len(errorString)
- total_01 = 0
- total_10 = 0
- count_0 = 0
- count_1 = 0
- for char in errorString:
- if char == '0':
- total_10 += count_1
- count_0 += 1
- elif char == '1':
- total_01 += count_0
- count_1 += 1
- min_errors_0 = total_01 * x
- min_errors_1 = total_10 * y
- for char in errorString:
- if char == '!':
- count_0 += 1
- min_errors_0 += total_10 * y
- min_errors_0 %= MOD
- count_1 += 1
- min_errors_1 += total_01 * x
- min_errors_1 %= MOD
- return min(min_errors_0, min_errors_1)
- # Ejemplo de uso
- errorString = "1011!"
- x = 2
- y = 3
- print(getMinErrors(errorString, x, y)) # Salida esperada: 9
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement