#P10034. 「Cfz Round 3」Circle
「Cfz Round 3」Circle
Problem Description
You are given a string of length and a non-negative integer .
We define, for a permutation of and a non-negative integer :
$$f_{t,k}(i)=\begin{cases}i & k=0\\f_{t,k-1}(t_i) & k \neq 0\end{cases}$$You need to construct a permutation of such that:
- For any positive integer not greater than , .
- If is , then (if is , there is no restriction).
Or report that there is no solution.
A permutation of means a sequence in which every positive integer not greater than appears exactly once.
Input Format
This problem has multiple test cases.
The first line contains an integer , the number of test cases.
Then each test case is given as follows:
- The first line contains two integers .
- The second line contains a string of length , denoted as .
Output Format
For each test case, output one line:
- If there exists a permutation that satisfies the conditions, output integers separated by spaces, representing the permutation you constructed.
- Otherwise, output .
Any output that meets the requirements will be accepted.
4
5 3
10011
4 5
1000
5 6
11111
9 6
011111011
4 3 2 5 1
-1
5 4 2 3 1
3 1 2 6 4 5 9 7 8
Hint
"Sample Explanation #1"
For the st test case, , and the other positions are similar, so when is , it satisfies the conditions.
For the nd test case, it can be proved that there is no permutation that satisfies the conditions.
For the rd test case, is also a permutation that satisfies the conditions.
Constraints
Let denote the sum of within a single test point.
For all testdata, , , , , and is guaranteed to contain only and .
You can get the score only if you pass all test points of this problem.
Translated by ChatGPT 5