Problem:
Largest Square

Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.

Input

H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W

In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.

Output

Print the area (the number of 0s) of the largest square.

Constraints

1 ≤ H, W ≤ 1,400

Sample Input

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

Sample Output

4

Solution in C# (judge verdict: Wrong Answer)

using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
class Solve{
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        string[] str = Console.ReadLine().Split(' ');
        int H = int.Parse(str[0]);
        int W = int.Parse(str[1]);
        bool[,] b = new bool[H,W];
        for(int i=0;i<H;i++){
            str = Console.ReadLine().Split(' ');
            for(int j=0;j<W;j++){
                b[i,j] = str[j] == "1";
            }
        }
        int[,] L = new int[H,W];
        for(int i=0;i<H;i++){
            int p = 0;
            for(int j=0;j<W;j++){
                if(b[i,j]){
                    p = j+1;
                }
                L[i,j] = p;
            }
        }
        int[,] U = new int[H,W];
        for(int i=0;i<W;i++){
            int p = 0;
            for(int j=0;j<H;j++){
                if(b[j,i]){
                    p = j+1;
                }
                U[j,i] = p;
            }
        }
        int[,] DP = new int[H,W];
        int max = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(!b[i,j]){
                    if(i == 0 || j == 0){
                        DP[i,j] = 1;
                    }
                    else{
                        int min = DP[i-1,j-1] + 1;
                        min = Math.Min(min,j-L[i,j]+1);
                        min = Math.Min(min,i-U[i,j]+1);
                        DP[i,j] = min;
                    }
                    max = Math.Max(max,DP[i,j]);
                }
            }
        }
        sb.Append(max+"\n");
    }
}