#K82652. Robot Rearrangement
Robot Rearrangement
Robot Rearrangement
You are given several configurations of a square board with dimension \(n\). Each configuration consists of \(n\) strings representing the rows of the board. Each row must contain exactly one robot, indicated by the character 'R'.
Your task is to determine whether the given configuration can be considered valid for the purpose of rearranging the robots such that no two robots share the same row or column.
A configuration is valid if and only if:
- Each row contains exactly one 'R'.
- The columns in which the 'R' appears in each row are all distinct.
For each test case, output YES
if the configuration is valid, and NO
otherwise.
The input is read from standard input and the results should be printed to standard output.
inputFormat
The input begins with an integer \(T\) \( (1 \leq T \leq 100)\) denoting the number of test cases. Each test case is formatted as follows:
- An integer \(n\) \( (1 \leq n \leq 1000)\), representing the number of rows (and columns) of the board.
- \(n\) lines follow, each line is a string of length \(n\) representing a row of the board. Each string consists of characters where 'R' denotes a robot and '.' denotes an empty cell.
It is guaranteed that the board consists only of the characters 'R' and '.'.
outputFormat
For each test case, output a single line containing either YES
or NO
. YES
if the configuration is valid (i.e., each row contains exactly one 'R' and all 'R's are in distinct columns) and NO
otherwise.
2
3
R..
.R.
..R
4
R...
....
.R..
..R.
YES
NO
</p>