QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#6442. 天遒谷的秘密

Estadísticas

在天遒谷遗迹的北塔中,有一些火焰火把谜题,旅行者荧正面临着最后一个也是最难的一个。

来源:原神官方

圆环上有 $n$ 个火把,初始时部分火把已被点燃。对于所有 $1 \le i \le n$,第 $i$ 个火把与第 $(i \pmod n + 1)$ 个火把相邻。

为了解开谜题,所有的火把都必须被点燃。在每一步操作中,荧可以点燃一个熄灭的火把,而相邻火把的状态会受到超自然力量的影响而反转。也就是说,如果相邻火把当前是熄灭的,它将被点燃;如果当前是点燃的,它将被熄灭。

时间就是金钱,荧希望在 $2n$ 步内解开谜题,或者确定该谜题无法解开。

输入格式

输入包含多组测试数据。第一行包含一个整数 $T$,表示测试数据的组数。对于每组测试数据:

第一行包含一个整数 $n$ ($3 \le n \le 10^5$),表示圆环上火把的数量。

第二行包含一个长度为 $n$ 的二进制字符串 $s_1s_2 \dots s_n$ ($s_i \in \{‘0’, ‘1’\}$)。如果 $s_i = ‘0’$,则第 $i$ 个火把初始时是熄灭的;如果 $s_i = ‘1’$,则第 $i$ 个火把初始时是点燃的。保证初始时并非所有火把都已被点燃。

保证所有测试数据的 $n$ 之和不超过 $10^6$。

输出格式

如果谜题无法解开,输出 “0”(不含引号)。

否则,在第一行输出一个整数 $k$ ($1 \le k \le 2n$),表示荧解开谜题所需的步数。然后在下一行输出 $k$ 个整数 $t_1, t_2, \dots, t_k$,中间用空格分隔,其中 $t_i$ 表示荧在第 $i$ 步点燃第 $t_i$ 个火把。如果存在多种答案,输出任意一种即可。

请注意,不要在每行末尾输出多余的空格,否则你的答案可能会被判为错误!

样例

输入 1

2
5
00000
3
001

输出 1

7
2 5 1 2 3 4 2
0

说明

对于第一个样例测试数据,火把的状态变化如下:$00000 \to 11100 \to 01111 \to 10110 \to 01010 \to 00100 \to 00011 \to 11111$。

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.