#P10055. [CCO 2022] Good Game
[CCO 2022] Good Game
Problem Description
Finn is playing a game called Twos and Threes. Twos and Threes is a single-player game played on a one-dimensional board. In the initial position, there are tiles in a row, and each tile is labeled or . The tiles are numbered from left to right from to . Finn can perform the following move:
- Choose or consecutive tiles that have the same label, remove them from the board, and then connect the remaining tiles and renumber them from left to right.
If all tiles on the board are removed, Finn wins the game. Your task is to help Finn find a sequence of moves that wins the game, or determine that the game cannot be won.
Input Format
The first line contains an integer .
The second line contains a string , representing the labels at the start of the game. has characters, and each character of is either or .
Output Format
If there exists a winning sequence of moves, output on the first line, the number of moves in the sequence. In the next lines, output two integers separated by a space, indicating a move that removes the tiles in .
If there is no winning sequence of moves, output .
If there are multiple winning sequences of moves, you may output any one of them.
9
ABAABBBAA
4
6 2
3 2
2 2
1 3
Hint
Sample Explanation
The moves are as follows:
$$\begin{aligned} &\tt{ABAAB\underline{BB}AA}\\ &\tt{AB\underline{AA}BAA}\\ &\tt{A\underline{BB}AA}\\ &\tt{\underline{AAA}}\\ \end{aligned}$$Constraints
For all testdata, .
| Subtask ID | Points | Range of |
|---|---|---|
Hint
Translated by ChatGPT 5