#C992. Largest Square Area in a Binary Matrix

    ID: 54066 Type: Default 1000ms 256MiB

Largest Square Area in a Binary Matrix

Largest Square Area in a Binary Matrix

You are given a binary matrix (i.e., a matrix containing only 0s and 1s) with n rows and m columns. Your task is to find the area of the largest square sub-matrix that is entirely filled with 1s.

If the side length of the largest square is l, then the area is given by the formula: \(A = l^2\).

The matrix will be provided via standard input. The first line contains two integers n and m. The following n lines each contain m integers (0 or 1) separated by spaces. You are required to print the area of the largest square (i.e., the maximum area) to standard output.

inputFormat

The input begins with a line containing two integers \(n\) and \(m\) representing the number of rows and columns of the matrix respectively. The next \(n\) lines contain \(m\) space-separated integers (either 0 or 1) representing the matrix.

Example:

4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0

outputFormat

Output a single integer, which is the area of the largest square sub-matrix consisting entirely of 1s.

Example:

4
## sample
4 5
1 0 1 0 0
1 0 1 1 1
1 1 1 1 1
1 0 0 1 0
4

</p>