There a string given with 0, 1 and ! where ! is an error and can be replaced by either 0 or 1 and there is x and y given where the function to calculate the error is no of 01 subsequence * x + no of 10 subsequence * y. We have to calculate the minimum of above function by replacing the ! with either 0 or 1. It can be either 0 or 1 for all the !.
Constraints: len(string) <= 10^5
For eg;
Input: 01!0, x = 2, y = 3
! -> 0 => 0100
no of 01 - 1
no. of 10 - 2
=> 2 * 1 + 3 * 2 = 8

! -> 1 => 0110
no of 01 - 2
no. of 10 - 2
=> 2 * 2 + 2 * 3 = 10

So the min is 8 that is the output.
There is no co-relation between ! so they can be independently set to 0 or 1 if there are mulitples.

Input: !!!!!!!, x=23, y=47
Output = 0

Comments (11)