GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 10 June 2022

[Solution] Lena and Matrix Codeforces Solution | Codeforces Problem Solution 2022

D. Lena and Matrix
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Lena is a beautiful girl who likes logical puzzles.

As a gift for her birthday, Lena got a matrix puzzle!

The matrix consists of n rows and m columns, and each cell is either black or white. The coordinates (i,j) denote the cell which belongs to the i-th row and j-th column for every 1in and 1jm. 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 k1 black cells in the matrix with coordinates (xi,yi) for every 1ik. Lena should choose a cell (a,b) that minimizes

Solution Click Below:-  CLICK HERE


    As Lena has no skill, she asked you for help. Will you tell her the optimal cell to choose?

    Input

    There are several test cases in the input data. The first line contains a single integer t (1t10000) — the number of test cases. This is followed by the test cases description.

    The first line of each test case contains two integers n and m (2n,m1000)  — the dimensions of the matrix.

    The following n lines contain m characters each, each character is either 'W' or 'B'. The j-th character in the i-th of these lines is 'W' if the cell (i,j) is white, and 'B' if the cell (i,j) is black.

    It is guaranteed that at least one black cell exists.

    It is guaranteed that the sum of nm does not exceed 106.

    Output

    For each test case, output the optimal cell (a,b) to choose. If multiple answers exist, output any.

    No comments:

    Post a Comment