TaroFillingAStringDiv2
SRM 650 · 2015-01-29 · by Witaliy
Problem Statement
Cat Taro likes strings.
You are given a
To Taro, the ugliness of a string is the number of pairs of equal consecutive characters. For example, the ugliness of "ABABAABBB" is 3: there is one pair "AA" and two (overlapping) pairs "BB".
Taro now wants to change each question mark in S either to 'A' or to 'B'. His goal is to minimize the ugliness of the resulting string. Return the smallest ugliness that can be achieved.
Constraints
- S will contain between 1 and 50 characters, inclusive.
- S will consist only of characters 'A', 'B' and '?'.
"ABAA" Returns: 1
There is initially one pair of consecutive digits that are equal in this case. There is no characters that Taro has to replace, hence the answer is 1.
"??" Returns: 0
"A?A" Returns: 0
"A??B???AAB?A???A" Returns: 3
"?BB?BAAB???BAB?B?AAAA?ABBA????A?AAB?BBA?A?" Returns: 10
Submissions are judged against all 87 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TaroFillingAStringDiv2 with a public method int getNumber(string S) · 87 test cases · 2 s / 256 MB per case