var a:array[0..maxn,0..maxn]of boolean;
f:array[0..maxn,0..maxn]of longint;
ans,i,j,k,m,n,ii,jj,si,sj:longint;
flog:boolean;
begin
readln(m,n);
for i:=1 to m do
for j:=1 to n do
begin
read(k);
if k=1 then
begin
a[i,j]:=true;
f[i,j]:=1;
end
else
begin
a[i,j]:=false;
f[i,j]:=0;
end;
end;
for i:=2 to m do
for j:=2 to n do
begin
if not a[i,j] then continue;
if not a[i-1,j-1] then continue;
flog:=false;
k:=f[i-1,j-1];
si:=f[i-1,j];
// for ii:=i downto i-k do
// if a[ii,j] then inc(si);
sj:=f[i,j-1];
// for jj:=j downto j-k do
// if a[i,jj] then inc(sj);
if si>sj then f[i,j]:=sj else f[i,j]:=si;
if f[i,j]>k then f[i,j]:=k;
inc(f[i,j]);
// if f[i,j]=4 then writeln(i,j,'!');
end;
ans:=0;
for i:=1 to m do
for j:=1 to n do
if f[i,j]>ans then ans:=f[i,j];
writeln(ans*ans);
end.
连调试代码一同贴上来 大家应该就能看懂我的思路了。