[Solution] Lena and Matrix Codeforces Solution | Codeforces Problem Solution 2022
Lena is a beautiful girl who likes logical puzzles.
As a gift for her birthday, Lena got a matrix puzzle!
The matrix consists of rows and columns, and each cell is either black or white. The coordinates denote the cell which belongs to the -th row and -th column for every and . To solve the puzzle, Lena has to choose a cell that minimizes the Manhattan distance to the farthest black cell from the chosen cell.
More formally, let there be black cells in the matrix with coordinates for every . Lena should choose a cell that minimizes
As Lena has no skill, she asked you for help. Will you tell her the optimal cell to choose?
There are several test cases in the input data. The first line contains a single integer () — the number of test cases. This is followed by the test cases description.
The first line of each test case contains two integers and () — the dimensions of the matrix.
The following lines contain characters each, each character is either 'W' or 'B'. The -th character in the -th of these lines is 'W' if the cell is white, and 'B' if the cell is black.
It is guaranteed that at least one black cell exists.
It is guaranteed that the sum of does not exceed .
For each test case, output the optimal cell to choose. If multiple answers exist, output any.
No comments:
Post a Comment