Allons—y @ 2018-05-29 18:06:14
#include<iostream>
#include<cstdio>
#define size 2505
using namespace std;
int n,m;
bool data[size][size];
int sum1[size][size],sum2[size][size],maxlen;
short line1[size][size],line2[size][size];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
scanf("%d",&data[i][j]);
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
sum1[i][j]=sum1[i][j-1]+data[i][j];
sum2[i][j]=sum2[i-1][j]+sum1[i][j];
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(data[i][j]){
line1[i][j]=line1[i-1][j-1]+1;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(data[i][j]){
line1[i][j]=line1[i-1][j+1]+1;
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(line1[i][j]>maxlen){
if(line1[i][j]==sum2[i][j]-sum2[i-line1[i][j]][j]-sum2[i][j-line1[i][j]]+sum2[i-line1[i][j]][j-line1[i][j]]){
maxlen=line1[i][j];
}
}
}
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
if(line2[i][j]>maxlen){
if(line2[i][j]==sum2[i][j]-sum2[i-line2[i][j]][j]-sum2[i][j-line2[i][j]]+sum2[i-line2[i][j]][j-line2[i][j]]){
maxlen=line2[i][j];
}
}
}
}
printf("%d",maxlen);
return 0;
}