#K68427. Largest Square Area
Largest Square Area
Largest Square Area
You are given a grid with N rows and M columns, where each cell contains either 0 or 1. Your task is to find the area of the largest square sub-grid that consists entirely of 1s.
Formally, given a matrix \( grid \) of size \( N \times M \), determine the largest square (with sides parallel to the grid) where every cell is 1 and output the area of this square.
Note: A square of side length \( k \) has area \( k^2 \). If there is no square consisting solely of 1s, output 0.
inputFormat
The input is read from standard input (stdin) and has the following format:
N M row1 row2 ... rowN
Where:
N
andM
are two integers representing the number of rows and columns respectively.- Each of the next N lines contains M space-separated integers (either 0 or 1) representing the grid.
outputFormat
Output a single integer to standard output (stdout): the area of the largest square sub-grid composed entirely of 1s.
## sample5 6
1 0 1 0 0 1
1 0 1 1 1 1
1 1 1 1 1 0
0 0 1 1 1 1
1 1 1 1 1 1
9