#K3591. Largest Square Park

    ID: 25636 Type: Default 1000ms 256MiB

Largest Square Park

Largest Square Park

You are given a grid with n rows and m columns where each cell is either an obstacle (represented by 1) or an empty space (represented by 0). Your task is to find the area of the largest square composed entirely of empty cells. The area is computed as (side^2), where (side) is the length of the square's side. Use an efficient dynamic programming approach to solve this problem.

For example, given the grid:

5 6 1 0 1 0 0 1 1 0 0 0 0 1 1 0 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0

The largest square of zeros has a side length of 2, so its area is (2^2 = 4).

inputFormat

The first line contains two integers (n) and (m), representing the number of rows and columns of the grid respectively. This is followed by (n) lines, each containing (m) integers (either 0 or 1) separated by spaces.

outputFormat

Output a single integer - the area of the largest square consisting entirely of 0's.## sample

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