#K88037. Largest Special Submatrix
Largest Special Submatrix
Largest Special Submatrix
You are given a matrix with non-negative integers. Your task is to find the largest special submatrix where all elements are equal. The submatrix should be identified by its top‐left and bottom‐right coordinates (both inclusive) using 1-indexed notation.
A submatrix is defined by the coordinates ( (i, j) ) for the top‐left corner and ( (r, c) ) for the bottom‐right corner. Its area can be calculated as ( (r-i+1) \times (c-j+1) ). You are required to choose the submatrix with the maximum area such that all its elements are the same. If there are multiple special submatrices, output the one that appears first in the search (the algorithm is allowed to yield any valid maximum area submatrix, but typically a brute force search is performed).
The input is read from standard input and the result should be printed to standard output.
inputFormat
The first line contains two integers ( n ) and ( m ), representing the number of rows and columns in the matrix. The following ( n ) lines each contain ( m ) integers separated by spaces.
outputFormat
Output four space-separated integers representing the 1-indexed coordinates of the top-left and bottom-right corners of the largest special submatrix.## sample
4 5
1 1 1 2 2
1 1 1 2 2
1 1 1 3 3
4 4 4 4 4
1 1 3 3
</p>