atcoder#ARC150A. [ARC150A] Continuous 1

[ARC150A] Continuous 1

Score : 300300 points

Problem Statement

You are given a string of length NN, S=S1S2SNS=S_1S_2\dots S_N, consisting of 0, 1, and ?.

We like to replace every ? with 0 or 1 so that all of the following conditions are satisfied.

  • SS contains exactly KK occurrences of 1.
  • These KK occurrences of 1 are consecutive. That is, there is an i (1iNK+1)i\ (1 \leq i \le N-K+1) such that Si=Si+1==Si+K1=S_i=S_{i+1}=\dots=S_{i+K-1}= 1.

Determine whether there is exactly one way to replace the characters to satisfy the conditions.

You have TT test cases to solve.

Constraints

  • 1T1051 \leq T \leq 10^5
  • 1K<N3×1051 \leq K < N \leq 3 \times 10^5
  • SS is a string of length NN consisting of 0, 1, and ?.
  • The sum of NN across the test cases is at most 3×1053 \times 10^5.

Input

The input is given from Standard Input in the following format:

TT

case1\mathrm{case}_1

\vdots

caseT\mathrm{case}_T

Each case is in the following format:

NN KK

SS

Output

Print TT lines. The ii-th line should contain Yes if, for the ii-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 SS into 101, for instance, does not satisfy the conditions since the 1s will not be consecutive. The only way to satisfy the conditions is to turn SS into 110.

For the second test case, we may turn SS 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.