atcoder#ARC150A. [ARC150A] Continuous 1
[ARC150A] Continuous 1
Score : points
Problem Statement
You are given a string of length , , consisting of 0
, 1
, and ?
.
We like to replace every ?
with 0
or 1
so that all of the following conditions are satisfied.
- contains exactly occurrences of
1
. - These occurrences of
1
are consecutive. That is, there is an such that1
.
Determine whether there is exactly one way to replace the characters to satisfy the conditions.
You have test cases to solve.
Constraints
- is a string of length consisting of
0
,1
, and?
. - The sum of across the test cases is at most .
Input
The input is given from Standard Input in the following format:
Each case is in the following format:
Output
Print lines. The -th line should contain Yes
if, for the -th test case, there is exactly one way to replace the characters to satisfy the conditions, and No
otherwise.
4
3 2
1??
4 2
?1?0
6 3
011?1?
10 5
00?1???10?
Yes
No
No
Yes
For the first test case, turning into 101
, for instance, does not satisfy the conditions since the 1
s will not be consecutive. The only way to satisfy the conditions is to turn into 110
.
For the second test case, we may turn into 1100
or 0110
to satisfy the conditions, so there are two ways to satisfy them.
For the third test case, there is no way to replace the characters to satisfy the conditions.