Canadian Computing Olympiad: 2022 Day 2, Problem 3
Finn is playing a game of Twos and Threes. Twos and Threes is a one-player game played
on a one-dimensional board. In the starting position, there are
- Select
or consecutive blocks that share the same label. Remove them from the board. Connect any remaining blocks together. Re-index the blocks from left to right, starting with index .
Finn wins the game if all blocks are removed from the board. Your task is to help Finn determine a winning sequence of moves, or determine if the game cannot be won.
Input Specification
The first line of input will contain the integer
The second line of input will contain the string
There are A
or B
.
Marks Awarded | Bounds on |
---|---|
Output Specification
If there is a winning sequence of moves, output
If there is no winning sequence of moves, output -1
.
If there are multiple winning sequences, then any winning sequence will be accepted. There is no need to minimize or maximize
Sample Input
9
ABAABBBAA
Possible Output for Sample Input
4
6 2
3 2
2 2
1 3
Explanation of Output for Sample Input
The sample output denotes this winning sequence:
Comments