#C1608. Largest Mirrored Submatrix

    ID: 44832 Type: Default 1000ms 256MiB

Largest Mirrored Submatrix

Largest Mirrored Submatrix

You are given a binary matrix of size (R \times C) consisting of characters '0' and '1'. Your task is to find the largest contiguous submatrix (with at least 2 rows and 2 columns) that is mirrored along its vertical axis. In other words, if the submatrix has width (w) and height (h), then for every row (i) ((1 \leq i \leq h)) and for every column (j) ((1 \leq j \leq w)), the following condition holds:

[ S[i][j] = S[i][w-j+1] ]

If multiple submatrices satisfy the condition, choose the one with the largest width; if there is a tie in width, choose the one with the largest height. If no valid submatrix exists, output (-1 -1).

inputFormat

The input is given via standard input (stdin). The first line contains two integers (R) and (C) separated by a space, representing the number of rows and columns respectively. The next (R) lines each contain a binary string of length (C) representing one row of the matrix.

outputFormat

Print two integers separated by a space on standard output (stdout): the number of rows and columns of the largest mirrored submatrix. If no valid mirrored submatrix exists, print (-1 -1).## sample

4 6
101101
110011
101101
111111
4 6

</p>