CF1889A.Qingshan Loves Strings 2

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Qingshan has a string ss which only contains 0\texttt{0} and 1\texttt{1}.

A string aa of length kk is good if and only if

  • ai≠ak−i+1a_i \ne a_{k-i+1} for all i=1,2,…,ki=1,2,\ldots,k.

For Div. 2 contestants, note that this condition is different from the condition in problem B.

For example, 10\texttt{10}, 1010\texttt{1010}, 111000\texttt{111000} are good, while 11\texttt{11}, 101\texttt{101}, 001\texttt{001}, 001100\texttt{001100} are not good.

Qingshan wants to make ss good. To do this, she can do the following operation at most 300300 times (possibly, zero):

  • insert 01\texttt{01} to any position of ss (getting a new ss).

Please tell Qingshan if it is possible to make ss good. If it is possible, print a sequence of operations that makes ss good.

青衫有一串只包含 0 和 1 的字符串 ss。

长度为 kk 的字符串 aa 被称为好串,当且仅当对所有 i=1,2,…,ki = 1, 2, \ldots, k,均满足

ai≠ak−i+1.a_i \ne a_{k-i+1}.

(对 Div. 2 参赛者提示:该条件与题目 B 中的条件不同。)

例如,10、1010、111000 是好串,而 11、101、001、001100 不是好串。

青衫希望将 ss 变为好串。为此,她最多可执行 300 次(也可以为 0 次)如下操作:

  • 在 ss 的任意位置插入子串 01(得到新的 ss)。

请告诉青衫:是否可能将 ss 变为好串?若可能,请输出一组操作序列,使得最终 ss 成为好串。

输入格式

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001\le t\le 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n\le 100) — the length of string ss, respectively.

The second line of each test case contains a string ss with length nn.

It is guaranteed that ss only consists of 0\texttt{0} and 1\texttt{1}.

输入包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001\le t\le 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n\le 100),表示字符串 ss 的长度。

每个测试用例的第二行包含一个长度为 nn 的字符串 ss。

保证字符串 ss 仅由字符 0\texttt{0} 和 1\texttt{1} 组成。

输出格式

For each test case, if it impossible to make ss good, output −1-1.

Otherwise, output pp (0≤p≤3000 \le p \le 300) — the number of operations, in the first line.

Then, output pp integers in the second line. The ii-th integer should be an index xix_i (0≤xi≤n+2i−20 \le x_i \le n+2i-2) — the position where you want to insert 01\texttt{01} in the current ss. If xi=0x_i=0, you insert 01\texttt{01} at the beginning of ss. Otherwise, you insert 01\texttt{01} immediately after the xix_i-th character of ss.

We can show that under the constraints in this problem, if an answer exists, there is always an answer that requires at most 300300 operations.

对于每个测试用例,如果无法使 ss 变为“好”的字符串,则输出 −1-1。

否则,在第一行输出 pp(0≤p≤3000 \le p \le 300)—— 所需操作的次数。

然后在第二行输出 pp 个整数。第 ii 个整数应为一个下标 xix_i(0≤xi≤n+2i−20 \le x_i \le n+2i-2),表示你希望在当前字符串 ss 的哪个位置插入 01\texttt{01}。若 xi=0x_i = 0,表示将 01\texttt{01} 插入到 ss 的开头;否则,表示将 01\texttt{01} 插入到 ss 的第 xix_i 个字符之后。

我们可以证明:在本题的约束条件下,若存在解,则必存在一个至多需要 300300 次操作的解。

输入输出样例

  • 输入#1

    6
    2
    01
    3
    000
    4
    1111
    6
    001110
    10
    0111001100
    3
    001

    输出#1

    0
    
    -1
    -1
    2
    6 7
    1
    10
    -1

说明/提示

In the first test case, you can do zero operations and get s=01s=\texttt{01}, which is good.

Another valid solution is to do one operation: (the inserted 01\texttt{01} is underlined)

  1. 001‾1\texttt{0}\underline{\texttt{01}}\texttt{1}

and get s=0011s = \texttt{0011}, which is good.

In the second and the third test case, it is impossible to make ss good.

In the fourth test case, you can do two operations:

  1. 00111001‾\texttt{001110}\underline{\texttt{01}}
  2. 001110001‾1\texttt{0011100}\underline{\texttt{01}}\texttt{1}

and get s=0011100011s = \texttt{0011100011}, which is good.

在第一个测试用例中,你可以执行零次操作,得到 s=01s=\texttt{01},这是一个“好”字符串。

另一个合法的解法是执行一次操作(插入的 01\texttt{01} 用下划线标出):

  1. 001‾1\texttt{0}\underline{\texttt{01}}\texttt{1}

从而得到 s=0011s = \texttt{0011},这也是一个“好”字符串。

在第二个和第三个测试用例中,无法使 ss 变为“好”字符串。

在第四个测试用例中,你可以执行两次操作:

  1. 00111001‾\texttt{001110}\underline{\texttt{01}}
  2. 001110001‾1\texttt{0011100}\underline{\texttt{01}}\texttt{1}

从而得到 s=0011100011s = \texttt{0011100011},这是一个“好”字符串。

输入解题思路,AI测评打分。不知道怎么写?

首页