z-board
Little Z is playing a game. Game is consisted of a coin and a rectangular board of r rows and [] columns. In order to explain game, we will consider that position (A, B) to refer to the field at row A and column B.
At the beginning of the game, the coin is placed at position (1, 1). The goal of the game is to move the coin to position (r, c). From position (x, y), the coin can be moved to position (x + 1, y), labeling with an upper-case letter 'D', or (x, y + 1), labeling with an upper-case letter 'R'. However, some fields of the board are broken and coin can't be placed on these fields. To make the game even harder, Little Z has to find K-th lexicographically smallest sequence of moves which will get the coin from the position (1, 1) to the position (r, c).
Sequence of moves is represented with letters 'D' and 'R', where i-th letter represents i-th move.
Be a kind friend, as Little Z is, and help him to find described path.
[c]4 4 5
....
....
....
....
Output:
DRDDRRExplanation:
5-th path is (1, 1) -> (2, 1) -> (2, 2) -> (3, 2) -> (4, 2) -> (4, 3) -> (4, 4).
4 5 11
....#
.....
.##..
.....Output:
RRRDDDRExplanation:
11-th path is (1, 1) -> (1, 2) -> (1, 3) -> (1, 4) -> (2, 4) -> (3, 4) -> (4, 4) -> (4, 5).
5 5 51
.....
.....
.....
.....
.....Output:
RDRDRRDD2 2 3
..
..Output:
impossibleExplanation:
There are only 2 possible sequences of moves - DR and RD.
Submit solution
Coming laterThe grading service will be connected in a later migration step. You can inspect the task and your previous results now.