#C7422. Largest Square of 1s

    ID: 51292 Type: Default 1000ms 256MiB

Largest Square of 1s

Largest Square of 1s

You are given a grid of integers containing only 0s and 1s. Your task is to determine the area of the largest square sub-grid that consists entirely of 1s.

The first line of input contains two positive integers n and m which specify the number of rows and columns of the grid respectively. Each of the next n lines contains m integers separated by spaces (either 0 or 1) representing the grid.

Input Format (stdin): The first line contains two integers, followed by n lines of grid rows.
Output Format (stdout): A single integer denoting the area of the largest square comprised entirely of 1s.

The optimal solution uses dynamic programming to compute the size of the largest square ending at each cell.

inputFormat

The input is given via standard input (stdin) in the following format:

n m
row1 (m integers separated by spaces)
row2
...
rown

Where n is the number of rows and m is the number of columns of the grid.

outputFormat

Output a single integer to standard output (stdout), which is the area of the largest square sub-grid that contains only 1s.

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