#P10034. 「Cfz Round 3」Circle

    ID: 11032 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP图论洛谷原创Special JudgeO2优化背包 DP素数判断,质数,筛法构造洛谷月赛链表

「Cfz Round 3」Circle

Problem Description

You are given a 01\tt{01} string SS of length nn and a non-negative integer ll.

We define, for a permutation tt of 1n1 \sim n and a non-negative integer kk:

$$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 pp of 1n1 \sim n such that:

  • For any positive integer ii not greater than nn, piip_i \neq i.
  • If SiS_i is 1\tt1, then fp,l(i)=if_{p,l}(i)=i (if SiS_i is 0\tt0, there is no restriction).

Or report that there is no solution.

A permutation of 1n1 \sim n means a sequence in which every positive integer not greater than nn appears exactly once.

Input Format

This problem has multiple test cases.

The first line contains an integer TT, the number of test cases.

Then each test case is given as follows:

  • The first line contains two integers n,ln, l.
  • The second line contains a 01\tt{01} string of length nn, denoted as SS.

Output Format

For each test case, output one line:

  • If there exists a permutation pp that satisfies the conditions, output nn integers separated by spaces, representing the permutation pp you constructed.
  • Otherwise, output 1-1.

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 11st test case, fp,3(1)=fp,2(4)=fp,1(5)=fp,0(1)=1f_{p,3}(1)=f_{p,2}(4)=f_{p,1}(5)=f_{p,0}(1)=1, and the other positions are similar, so when pp is {4,3,2,5,1}\{4,3,2,5,1\}, it satisfies the conditions.

For the 22nd test case, it can be proved that there is no permutation pp that satisfies the conditions.

For the 33rd test case, {2,1,4,5,3}\{2,1,4,5,3\} is also a permutation pp that satisfies the conditions.

Constraints

Let n\sum n denote the sum of nn within a single test point.

For all testdata, 1T1001 \le T \le 100, 2n5×1052 \le n \le 5\times 10^5, 0l10180 \le l \le 10^{18}, n5×105\sum n \le 5\times 10^5, and SS is guaranteed to contain only 0\tt{0} and 1\tt{1}.

You can get the score only if you pass all test points of this problem.

Translated by ChatGPT 5