AmazonOA #91
getMinErrors
Estimated MediumJudge-ready
Topics (AI-labelled)Prefix & RangesGreedyStrings
Replace each ! with 0 or 1; every index pair i<j forming 01 costs x, and every pair forming 10 costs y. First find the minimum total cost, then take it modulo 10⁹+7; do not compare costs after taking the modulus.
Input
The first line contains errorString (length 1..100000), and the second line contains x y (0..10⁹).
Output
Output a single integer answer.
Example 1
Input:
!!!!!!!
23 47
Output:
0
Example 2
Input:
0!1
2 5
Output:
4
Example 3
Input:
10
2 5
Output:
5
Example notes
Example 1: set everything to 0; there are no pairs of different values, cost 0. Example 2: choosing 001 or 011 both produce two 01 pairs, cost 4. Example 3: the only 10 subsequence costs 5.
Editorial
Loading solution…