zpf_13516358919 @ 2017-02-03 16:46:44
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
const int N=2510;
int f[N][N],map[N][N],l[N][N],r[N][N],n,m,maxf;
using namespace std;
int main()
{
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&map[i][j]);
for(int i=1;i<=m;i++)
{
int x1=1,y1=i;
while(x1<=n&&y1<=m)
{
if(map[x1][y1])
r[x1][y1]=r[x1-1][y1-1]+1;
x1++;y1++;
}
int x2=1,y2=i;
while(x2<=n&&y2>=1)
{
if(map[x2][y2])
l[x2][y2]=l[x2-1][y2+1]+1;
x2++;y2--;
}
}
for(int i=2;i<=n;i++)
{
int x1=i,y1=1;
while(x1<=n&&y1<=m)
{
if(map[x1][y1])
r[x1][y1]=r[x1-1][y1-1]+1;
x1++;y1++;
}
int x2=i,y2=m;
while(x2<=n&&y2>=1)
{
if(map[x2][y2])
l[x2][y2]=l[x2-1][y2+1]+1;
x2++;y2--;
}
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
f[i][j]=map[i][j]+f[i-1][j]+f[i][j-1]-f[i-1][j-1];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
{
if(r[i][j])
{
int x=r[i][j];
if(f[i][j]-f[i-x][j]-f[i][j-x]+f[i-x][i-x]==x)
maxf=max(x,maxf);
}
}
memset(f,0,sizeof(f));
for(int i=1;i<=n;i++)
for(int j=m;j>=1;j--)
f[i][j]=map[i][j]+f[i-1][j]+f[i][j+1]-f[i-1][j+1];
for(int i=1;i<=n;i++)
for(int j=m;j>=1;j--)
{
if(l[i][j])
{
int x=l[i][j];
if(f[i][j]-f[i-x][j]-f[i][j+x]+f[i-x][i+x]==x)
maxf=max(x,maxf);
}
}
cout<<maxf;
fclose(stdin);fclose(stdout);
return 0;
}
by coder107 @ 2017-02-11 21:30:11
请使用标准输入输出