AtCoder Grand Contest 045
翻译中…
Problem Statement
翻译中…
Given is a string $S$, where each character is 0, 1, or ?.
翻译中…
Consider making a string $S'$ by replacing each occurrence of ? with 0 or 1 (we can choose the character for each ? independently). Let us define the unbalancedness of $S'$ as follows:
翻译中…
- (The unbalancedness of
$S'$)$= \max \{$The absolute difference between the number of occurrences of0and1between the$l$-th and$r$-th character of$S$(inclusive)$:\ 1 \leq l \leq r \leq |S|\}$
翻译中…
Find the minimum possible unbalancedness of $S'$.
翻译中…
Constraints
翻译中…
$1 \leq |S| \leq 10^6$- Each character of
$S$is0,1, or?.
翻译中…
Input
翻译中…
Input is given from Standard Input in the following format:
翻译中…
S
翻译中…
Output
翻译中…
Print the minimum possible unbalancedness of $S'$.
翻译中…
样例
Input #1
0??
Output #1
1
We can make $S'=$ `010` and achieve the minimum possible unbalancedness of $1$.
Input #2
0??0
Output #2
2
Input #3
??00????0??0????0?0??00??1???11?1?1???1?11?111???1
Output #3
4
题目信息
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。