#C5688. Smallest Enclosing Rectangle of X's

    ID: 49364 Type: Default 1000ms 256MiB

Smallest Enclosing Rectangle of X's

Smallest Enclosing Rectangle of X's

You are given a grid representing a warehouse with n rows and m columns. Each cell in the grid is either . (an empty cell) or X (an obstacle). Your task is to find the smallest axis-aligned rectangle that encloses all the cells containing an X.

If at least one X is found, output the coordinates of the top-left and bottom-right corners of the rectangle using 1-indexed positions, in the format:

topleftbottomrighttop\, left\, bottom\, right

If no cell contains an X, output -1.

Input Format: The first line contains two integers n and m separated by a space. The next n lines each contains a string of length m representing the warehouse grid.

Output Format: Output a single line with four integers representing the top-left and bottom-right coordinates of the smallest bounding rectangle of all X cells. If there are no X cells, output -1.

inputFormat

The input begins with a line containing two integers n and m (1 ≤ n, m ≤ 1000), representing the number of rows and columns of the grid. This is followed by n lines, each containing a string of m characters. Each character is either a . (denoting an empty cell) or an X (denoting an obstacle).

outputFormat

If an X is present in the grid, print four integers top left bottom right (all 1-indexed) in one line, defining the smallest rectangle that contains all X cells. Otherwise, output -1.

## sample
3 4
....
.X..
..X.
2 2 3 3