CF1736D.Equal Binary Subsequences

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Everool has a binary string ss of length 2n2n . Note that a binary string is a string consisting of only characters 00 and 11 . He wants to partition ss into two disjoint equal subsequences. He needs your help to do it.

You are allowed to do the following operation exactly once.

  • You can choose any subsequence (possibly empty) of ss and rotate it right by one position.

In other words, you can select a sequence of indices b1,b2,,bmb_1, b_2, \ldots, b_m , where 1b1<b2<<bm2n1 \le b_1 < b_2 < \ldots < b_m \le 2n . After that you simultaneously set $$$$s_{b_1} := s_{b_m}, $$ $$ s_{b_2} := s_{b_1}, $$ $$ \ldots, $$ $$ s_{b_m} := s_{b_{m-1}}. $$

Can you partition ss into two disjoint equal subsequences after performing the allowed operation exactly once?

A partition of ss into two disjoint equal subsequences sps^p and sqs^q is two increasing arrays of indices p_1,p_2,ldots,p_np\_1, p\_2, \\ldots, p\_n and q_1,q_2,ldots,q_nq\_1, q\_2, \\ldots, q\_n , such that each integer from 11 to 2n2n is encountered in either pp or qq exactly once, sp=s_p_1s_p_2ldotss_p_ns^p = s\_{p\_1} s\_{p\_2} \\ldots s\_{p\_n} , sq=s_q_1s_q_2ldotss_q_ns^q = s\_{q\_1} s\_{q\_2} \\ldots s\_{q\_n} , and sp=sqs^p = s^q .

If it is not possible to partition after performing any kind of operation, report 1-1 .

If it is possible to do the operation and partition ss into two disjoint subsequences sps^p and sqs^q , such that sp=sqs^p = s^q , print elements of bb and indices of sps^p , i. e. the values p_1,p_2,ldots,p_np\_1, p\_2, \\ldots, p\_n$$.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1051 \le t \le 10^5 ). Description of the test cases follows.

The first line of each test case contains a single integer nn ( 1n1051 \le n \le 10^5 ), where 2n2n is the length of the binary string.

The second line of each test case contains the binary string ss of length 2n2n .

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5 .

输出格式

For each test case, follow the following output format.

If there is no solution, print 1-1 .

Otherwise,

  • In the first line, print an integer mm ( 0m2n0 \leq m \leq 2n ), followed by mm distinct indices b1b_1 , b2b_2 , ..., bmb_m (in increasing order).
  • In the second line, print nn distinct indices p1p_1 , p2p_2 , ..., pnp_n (in increasing order).

If there are multiple solutions, print any.

输入输出样例

  • 输入#1

    4
    2
    1010
    3
    100010
    2
    1111
    2
    1110

    输出#1

    0
    1 2
    2 3 5
    1 2 5
    3 2 3 4
    1 4
    -1

说明/提示

In the first test case, bb is empty. So string ss is not changed. Now sp=s1s2=10s^p = s_1 s_2 = \mathtt{10} , and sq=s3s4=10s^q = s_3s_4 = \mathtt{10} .

In the second test case, b=[3,5]b=[3,5] . Initially s3=0s_3=\mathtt{0} , and s5=1s_5=\mathtt{1} . On performing the operation, we simultaneously set s3=1s_3=\mathtt{1} , and s5=0s_5=\mathtt{0} .

So ss is updated to 101000 on performing the operation.

Now if we take characters at indices [1,2,5][1,2,5] in sps^p , we get s1=100s_1=\mathtt{100} . Also characters at indices [3,4,6][3,4,6] are in sqs^q . Thus sq=100s^q=100 . We are done as sp=sqs^p=s^q .

In fourth test case, it can be proved that it is not possible to partition the string after performing any operation.

首页