atcoder#AGC045B. [AGC045B] 01 Unbalanced
[AGC045B] 01 Unbalanced
Score : points
Problem Statement
Given is a string , where each character is 0
, 1
, or ?
.
Consider making a string by replacing each occurrence of ?
with 0
or 1
(we can choose the character for each ?
independently).
Let us define the unbalancedness of as follows:
- (The unbalancedness of ) The absolute difference between the number of occurrences of
0
and1
between the -th and -th character of (inclusive)
Find the minimum possible unbalancedness of .
Constraints
- Each character of is
0
,1
, or?
.
Input
Input is given from Standard Input in the following format:
Output
Print the minimum possible unbalancedness of .
0??
1
We can make 010
and achieve the minimum possible unbalancedness of .
0??0
2
??00????0??0????0?0??00??1???11?1?1???1?11?111???1
4