#C8052. Largest Square Submatrix
Largest Square Submatrix
Largest Square Submatrix
Given a binary matrix consisting only of 0s and 1s, your task is to compute the area of the largest square submatrix that contains only 1s. If no such submatrix exists, output 0.
You are provided with two integers representing the number of rows (n) and columns (m) of the matrix, followed by n lines each containing m space-separated integers (each either 0 or 1). The area of a square submatrix is defined as the square of its side length.
Note: The solution should use an efficient approach, for instance dynamic programming, to compute the maximum square submatrix area.
Example:
Input: 4 5 1 0 1 0 0 1 0 1 1 1 1 1 1 1 1 1 0 0 1 0</p>Output: 4
inputFormat
The first line of input contains two integers n and m — the number of rows and columns in the matrix.
The following n lines each contain m space-separated integers (either 0 or 1), representing the rows of the matrix.
If n or m is 0, the matrix is considered empty, and the output should be 0.
outputFormat
Output a single integer: the area of the largest square submatrix that contains only 1s. If no such submatrix exists, output 0.
## sample4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
4