#K7336. Largest Uniform Square Submatrix
Largest Uniform Square Submatrix
Largest Uniform Square Submatrix
You are given an integer n and an n × n matrix of integers. Your task is to determine the size of the largest square submatrix that consists entirely of the same integer.
A submatrix is a contiguous block of rows and columns in the original matrix. For example, consider a 4×4 matrix. If one of its submatrices is a 2×2 square where all elements are equal, then the answer should be 2. Your solution should efficiently find this maximal square size using an appropriate algorithm like dynamic programming.
Note: If no square larger than 1×1 exists where all elements are the same, then the answer is 1.
inputFormat
The input is provided via stdin
and is formatted as follows:
- The first line contains an integer n, representing the dimension of the matrix.
- The following n lines each contain n space-separated integers representing the matrix rows.
outputFormat
Output a single integer to stdout
representing the size of the largest square submatrix in which all elements are identical.
4
1 2 3 4
5 5 5 5
5 5 5 5
7 8 9 0
2