题目描述
You are given an integer N and a (0-indexed) binary string A having length N+1.
Find any permutation P of {0,1,2,...,N-1} (or determine that it does not exist) that satisfies the following conditions for all i (0 ≤ i ≤ N):
if A_{i} = 0: No contiguous segment of $P has \texttt{mex}$ equal to i
if A_{i} = 1: There exists at least one contiguous segment of P that has $\texttt{mex}$ equal to i
If multiple permutations exist that satisfy the given conditions, print any.
Note: $\texttt{mex}$ of a segment is the smallest non-negative number that does not occur in that segment.
------ Input Format ------
- The first line contains the number of test cases T. Description of the test cases follows.
- The first line of each test case contains a single integer N.
- The second line of each test case contains the binary string A of length N + 1.
------ Output Format ------
For each test case print :
- $\texttt{Yes}$ if there exists a permutation P that satisfies the conditions described in the statement, followed by the permutation P in the next line (If multiple permutations exist that satisfy the given conditions, print any).
- $\texttt{No}$ otherwise.
You may print each character of $\texttt{Yes}$ and $\texttt{No}$ in uppercase or lowercase (for example$, \texttt{yes}, \texttt{yEs}, \texttt{YES}$ will be considered identical).
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$2 ≤ N ≤ 3 \cdot 10^{5}$
$|A| = N + 1$
- It is guaranteed that the sum of $N$ over all test cases does not exceed $3 \cdot 10^{5}$.
----- Sample Input 1 ------
4
2
111
5
110100
5
110101
7
11100111
----- Sample Output 1 ------
Yes
0 1
No
Yes
0 2 1 4 3
Yes
0 1 3 4 2 5 6
----- explanation 1 ------
Test case-1: One of the possible permutations satisfying the given conditions is [$0, 1$] because:
- $\texttt{mex}([1]) = 0$. Therefore the condition is satisfied for $i = 0$.
- $\texttt{mex}([0]) = 1$. Therefore the condition is satisfied for $i = 1$.
- $\texttt{mex}([0, 1]) = 2$. Therefore the condition is satisfied for $i = 2$.
Test case-2: It can be proven that no permutation exists that satisfies the given conditions.
Test case-3: One of the possible permutations satisfying the given conditions is [$0, 2, 1, 4, 3$] because:
- $\texttt{mex}([2]) = 0$. Therefore the condition is satisfied for $i = 0$.
- $\texttt{mex}([0, 2]) = 1$. Therefore the condition is satisfied for $i = 1$.
- There does not exist any segment with $\texttt{mex} = 2$. Therefore the condition is satisfied for $i = 2$.
- $\texttt{mex}([0, 2, 1]) = 3$. Therefore the condition is satisfied for $i = 3$.
- There does not exist any segment with $\texttt{mex} = 4$. Therefore the condition is satisfied for $i = 4$.
- $\texttt{mex}([0, 2, 1, 4, 3]) = 5$. Therefore the condition is satisfied for $i = 5$.
输入格式
见题面
输出格式
见题面