QOJ.ac

QOJ

时间限制: 1 s 内存限制: 2048 MB 总分: 25 难度: [显示]
统计

Finn 正在玩一个名为“二与三”(Twos and Threes)的游戏。这是一个在一维棋盘上进行的单人游戏。初始状态下,有 $N$ 个方块排成一行,每个方块上标记着 $A$ 或 $B$。方块从左到右编号为 $1$ 到 $N$。Finn 可以进行以下形式的操作:

  • 选择 $2$ 或 $3$ 个标签相同的连续方块,将它们从棋盘上移除。将剩余的方块连接在一起,并从左到右重新编号,起始编号为 $1$。

如果所有方块都被从棋盘上移除,Finn 就赢得了游戏。你的任务是帮助 Finn 确定一个获胜的操作序列,或者判断该游戏无法获胜。

输入格式

输入的第一行包含一个整数 $N$。

输入的第二行包含一个字符串 $S$,表示游戏的初始状态。$S$ 中有 $N$ 个字符,每个字符均为 $A$ 或 $B$。

分值 $N$ 的数据范围
3 分 $1 \le N \le 15$
6 分 $1 \le N \le 300$
7 分 $1 \le N \le 6000$
9 分 $1 \le N \le 10^6$

输出格式

如果存在获胜的操作序列,输出 $K$,即获胜序列中的操作次数。在接下来的 $K$ 行中,每行输出一个索引 $i$ 和一个数字 $j$,表示一次移除当前索引从 $i$ 到 $i + j - 1$(包含两端)的方块的操作。

如果不存在获胜的操作序列,输出 $-1$。

如果存在多个获胜序列,输出其中任意一个即可。无需最小化或最大化 $K$。

样例

输入格式 1

9
ABAABBBAA

输出格式 1

4
6 2
3 2
2 2
1 3

说明 1

样例输出表示了以下获胜序列:

$ABAAB\underline{BB}AA$ $ABA\underline{AB}AA$ $A\underline{BB}AA$ $\underline{AAA}$

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.