QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100 难度: [顯示]

#4244. 圆环转换

统计

你有两个由 0 和 1 组成的字符串 $s_0, s_1, \dots, s_{n-1}$ 和 $t_0, t_1, \dots, t_{n-1}$。

在一次操作中,你可以选择一个 $i$,使得 $s_i = s_{(i+1) \bmod n}$,然后将 $s_i$ 和 $s_{(i+1) \bmod n}$ 取反。取反意味着如果 $s_i$ 原本为 '1',则将其设为 '0',否则将其设为 '1'。

你的目标是在最多 $100\,000$ 次操作内,使得对于所有的 $i$,都有 $s_i = t_i$。

在本题的每个测试用例中,解总是存在的。注意,对于某些字符串对,你无法通过操作将一个转换为另一个(例如 “0101” 和 “1010”),但本题的测试数据中不会出现此类字符串。

输入格式

第一行包含一个二进制字符串 $s$。 第二行包含一个二进制字符串 $t$。 $2 \le |s| = |t| \le 100$。

输出格式

第一行输出 $m$ ($0 \le m \le 100\,000$):操作次数。 下一行输出 $m$ 个整数 $i_1, i_2, \dots, i_m$ ($0 \le i_j \le n - 1$):你需要执行操作的顺序。注意,当你对索引 $i$ 执行操作时,$s_i$ 必须等于 $s_{(i+1) \bmod n}$,且操作后 $s_i$ 和 $s_{(i+1) \bmod n}$ 的值会发生改变。

注意,你不一定需要最小化 $m$。

保证至少存在一个解。如果有多个可能的解,你可以输出其中任意一个。

样例

样例输入 1

000
011

样例输出 1

1
1

样例输入 2

0000
1111

样例输出 2

2
0
2

样例输入 3

110
011

样例输出 3

2
0
1

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.