Codeforces Round 1046 (Div. 2)
B
Like the Bitset
Codeforces
900
原题
← AC →
翻译中…

You are given a binary string$^{\text{∗}}$ $s$ of length $n$, as well as an integer $k$.

翻译中…

Aquawave wants to construct a permutation$^{\text{†}}$ $p$ of length $n$, so that for each $1\le i\le n$, where $s_i=\mathtt{1}$, the following holds:

翻译中…
  • For each interval $[l, r]$ ($1\le l\le r\le n$) whose length is at least $k$ (i.e. $r - l + 1 \geq k$), if it covers position $i$ (i.e. $l \leq i \leq r$), then the maximum element among $p_l, p_{l+1}, \ldots, p_r$ is not $p_i$.
翻译中…

Note that there are no such constraints on indices with $s_i = \mathtt{0}$.

翻译中…

You have to find such a permutation, or determine that such permutations do not exist.

翻译中…

$^{\text{∗}}$A binary string is a string where each character is either $\mathtt{0}$ or $\mathtt{1}$.$^{\text{†}}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in arbitrary order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation ($2$ appears twice in the array), and $[1,3,4]$ is also not a permutation ($n=3$ but there is $4$ in the array).

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $k$ ($1 \leq n \leq 2 \cdot 10^5$, $1 \leq k \leq n$) — the length of $s$ and the integer in the statements.

翻译中…

The second line contains the binary string $s$ of length $n$ ($s_i = \mathtt{0}$ or $\mathtt{1}$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case:

翻译中…
  • If there is at least one possible permutation:
  • Print "YES" in the first line of output;
    • Then, print $n$ integers $p_1, p_2, \ldots, p_n$ ($1 \leq p_i \leq n$, all $p_i$-s are distinct) in the second line — the permutation you constructed.
  • Otherwise, print "NO" in the single line of output.
翻译中…

You can output the tokens in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

翻译中…

If there are multiple answers, you may output any of them.

翻译中…

Note

翻译中…

In the first test case, you can output an arbitrary permutation of length $n = 2$, since all $s_i$-s are equal to $\mathtt{0}$.

翻译中…

In the second test case, $p=[1, 4, 3, 2]$ is a valid answer because:

翻译中…
  • The only position where $s_i = \tt{1}$ is $i = 3$. There are three distinct intervals $[l, r]$ covering index $3$, whose length is at least $k=3$: $[1, 3]$, $[1, 4]$, and $[2, 4]$;
  • And, for each of the three intervals, the maximum element among $p_l, \ldots, p_r$ should be $p_2 = 4$, which is not equal to $p_3 = 3$.
翻译中…

样例

Input #1
6
2 1
00
4 3
0010
5 2
11011
7 5
1111110
8 4
00101011
10 2
1000000010
Output #1
YES
1 2
YES
1 4 3 2
NO
NO
YES
6 5 2 3 4 8 1 7
YES
1 2 3 4 5 6 7 9 8 10
InputCopy OutputCopy
题目信息
题号
2136B
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。