#P3551. Take-out Game Elimination Sequence
Take-out Game Elimination Sequence
Take-out Game Elimination Sequence
Little Edna has received the take‐out game as a present. In this single‐player game, a row of (n) blocks is given, numbered from (1) to (n). Each block is either black or white. It is guaranteed that there are exactly (k) times as many white blocks as black blocks, i.e. if there are (b) black blocks then there are (k, b) white blocks and (n=(k+1)b).
The goal is to remove all the blocks using a sequence of permissible moves. In a single move, you must remove exactly (k+1) blocks: (k) white blocks and (1) black block. However, the move is only allowed if the blocks removed are consecutive in the current configuration (i.e. there is no gap between any two removed blocks). Note that the positions of the blocks do not change as blocks are removed (gaps remain), so a move always must select a contiguous segment (with respect to remaining blocks) that, when mapped to their original positions, forms a consecutive interval without any previously removed blocks in between.
A valid solution is a sequence of moves such that after performing them in order, all blocks are removed. It is guaranteed that at least one valid sequence exists.
inputFormat
The input consists of two lines. The first line contains two integers (n) and (k), where (n) is the total number of blocks and (k) is the multiplier for the number of white blocks relative to black blocks. The second line contains a string of length (n) consisting only of characters 'W' and 'B', representing white and black blocks respectively. It is guaranteed that the number of white blocks is exactly (k) times the number of black blocks (i.e. (n=(k+1)b) for some (b)).
outputFormat
First, output an integer (m) denoting the number of moves (which should be equal to the number of black blocks). Then output (m) lines. Each line represents one move and contains (k+1) space‐separated integers in increasing order, representing the original positions of the blocks removed in that move. The moves must be performed in the order given, and each move must remove a contiguous segment in the current configuration.
sample
3 2
WBW
1
1 2 3
</p>