QOJ.ac

QOJ

Límite de tiempo: 1.0 s Límite de memoria: 256 MB Puntuación total: 100 Hackeable ✓

#17291. 青山喜欢字符串 2

Estadísticas

Qingshan 有一个仅包含 01 的字符串 $s$。

一个长度为 $k$ 的字符串 $a$ 是好的,当且仅当:

  • 对于所有 $i = 1, 2, \dots, k$,都有 $a_i \neq a_{k-i+1}$。

对于 Div. 2 的参赛者,请注意此条件与问题 B 中的条件不同。

例如,101010111000 是好的,而 11101001001100 不是好的。

Qingshan 想要使 $s$ 变好。为此,她可以进行以下操作最多 $300$ 次(可能为零次):

  • 在 $s$ 的任意位置插入 01(从而得到一个新的 $s$)。

请告诉 Qingshan 是否有可能使 $s$ 变好。如果可能,请输出一个能使 $s$ 变好的操作序列。

输入格式

输入包含多个测试用例。第一行包含一个整数 $t$ ($1 \le t \le 100$) — 测试用例的数量。接下来是测试用例的描述。

每个测试用例的第一行包含一个整数 $n$ ($1 \le n \le 100$) — 字符串 $s$ 的长度。

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

保证 $s$ 仅由 01 组成。

输出格式

对于每个测试用例,如果无法使 $s$ 变好,输出 -1

否则,在第一行输出 $p$ ($0 \le p \le 300$) — 操作的次数。

然后,在第二行输出 $p$ 个整数。第 $i$ 个整数应当是一个下标 $x_i$ ($0 \le x_i \le n+2i-2$) — 表示你想要在当前 $s$ 中插入 01 的位置。如果 $x_i = 0$,你将在 $s$ 的开头插入 01。否则,你将在 $s$ 的第 $x_i$ 个字符之后立即插入 01

可以证明,在本题的限制条件下,如果存在解,则一定存在一个最多需要 $300$ 次操作的解。

样例

输入 1

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

输出 1

0

-1
-1
2
6 7
1
10
-1

说明

在第一个测试用例中,你可以进行零次操作并得到 $s = 01$,它是好的。

另一个有效的解是进行一次操作:(插入的 01 用下划线标出)

  1. $0\underline{01}1$

并得到 $s = 0011$,它是好的。

在第二个和第三个测试用例中,无法使 $s$ 变好。

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

  1. $001110\underline{01}$
  2. $0011100\underline{01}1$

并得到 $s = 0011100011$,它是好的。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.