PerMEXuation
You are given an integer
and a (-indexed) binary string having length .
Find any permutation of (or determine that it does not exist) that satisfies the following conditions for all ():
- if : No contiguous segment of has equal to
- if : There exists at least one contiguous segment of that has equal to
If multiple permutations exist that satisfy the given conditions, print any.
Note: 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 . Description of the test cases follows.
- The first line of each test case contains a single integer .
- The second line of each test case contains the binary string of length .
Output Format
For each test case print :
- if there exists a permutation that satisfies the conditions described in the statement, followed by the permutation in the next line (If multiple permutations exist that satisfy the given conditions, print any).
- otherwise.
You may print each character of and in uppercase or lowercase (for example, , , will be considered identical).
Constraints
- It is guaranteed that the sum of over all test cases does not exceed .
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
Test case-1: One of the possible permutations satisfying the given conditions is [] because:
- . Therefore the condition is satisfied for .
- . Therefore the condition is satisfied for .
- . Therefore the condition is satisfied for .
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 [] because:
- . Therefore the condition is satisfied for .
- . Therefore the condition is satisfied for .
- There does not exist any segment with . Therefore the condition is satisfied for .
- . Therefore the condition is satisfied for .
- There does not exist any segment with . Therefore the condition is satisfied for .
Comments
Post a Comment