Stable Arrangement of Rooks solution codeforces
You have anchessboard and rooks. Rows of this chessboard are numbered by integers from to from top to bottom and columns of this chessboard are numbered by integers from to from left to right. The cell is the cell on the intersection of row and collumn for and .
The arrangement of rooks on this board is called good, if no rook is beaten by another rook.
A rook beats all the rooks that shares the same row or collumn with it.
The good arrangement of rooks on this board is called not stable, if it is possible to move one rook to the adjacent cell so arrangement becomes not good. Otherwise, the good arrangement is stable. Here, adjacent cells are the cells that share a side.
The first line contains a single integer( ) — the number of test cases.
The first line of each test case contains two integers, ( ) — the size of the chessboard and the number of rooks.
If there is a stable arrangement of . and R. The -th symbol of the -th line should be equals R if and only if there is a rook on the cell in your arrangement.rooks on the chessboard, output lines of symbols
If there are multiple solutions, you may output any of them.
If there is no stable arrangement, output.
5 3 2 3 3 1 1 5 2 40 33
output Stable Arrangement of Rooks solution codeforces
..R ... R.. -1 R ..... R.... ..... ....R ..... -1
In the first test case, you should find stable arrangement ofrooks on the chessboard. Placing them in cells and gives stable arrangement.
In the second test case it can be shown that it is impossbile to placerooks on the chessboard to get stable arrangement.