

Time Limit: 2 sec / Memory Limit: 256 MB
配点 : 点
問題文
0
と 1
からなる文字列 が与えられます。
以下の操作を好きな回数繰り返すことで の要素をすべて 0
にできるような、 以下の最大の整数 を求めてください。
- の長さ 以上の連続する区間 を選ぶ(すなわち、 が満たされる必要がある)。 なるすべての整数 に対し、 が
0
なら を1
に、 が1
なら を0
に置き換える。
制約
- は
0
または1
である
入力
入力は以下の形式で標準入力から与えられる。
出力
操作を好きな回数繰り返すことで の要素をすべて 0
にできるような 最大の (21:08 JST 修正) 整数 を出力せよ。
入力例 1Copy
010
出力例 1Copy
2
以下の操作で、 の要素をすべて 0
にできます。
- 長さ の区間 に操作を行う。 は
101
になる。 - 長さ の区間 に操作を行う。 は
011
になる。 - 長さ の区間 に操作を行う。 は
000
になる。
入力例 2Copy
100000000
出力例 2Copy
8
入力例 3Copy
00001111
出力例 3Copy
4
Score : points
Problem Statement
You are given a string consisting of 0
and 1
.
Find the maximum integer not greater than such that we can turn all the characters of into 0
by repeating the following operation some number of times.
- Choose a contiguous segment in whose length is at least (that is, must be satisfied). For each integer such that , do the following: if is
0
, replace it with1
; if is1
, replace it with0
.
Constraints
- is either
0
or1
.
Input
Input is given from Standard Input in the following format:
Output
Print the maximum integer such that we can turn all the characters of into 0
by repeating the operation some number of times.
Sample Input 1Copy
010
Sample Output 1Copy
2
We can turn all the characters of into 0
by the following operations:
- Perform the operation on the segment with length . is now
101
. - Perform the operation on the segment with length . is now
011
. - Perform the operation on the segment with length . is now
000
.
Sample Input 2Copy
100000000
Sample Output 2Copy
8
Sample Input 3Copy
00001111
Sample Output 3Copy
4