囧雪诺 @ 2020-02-16 13:28:29
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
//freopen("C:\\Users\\1\\Desktop\\P1736.txt","r",stdin);
int n,m,maxv=0;
cin>>n>>m;
int a[n+5][m+5],f[n+5][m+5],f2[n+5][m+5];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
cin>>a[i][j];
if((i==1||j==1)&&a[i][j]==1) {
f[i][j]=1; maxv=1;
}
else f[i][j]=0;
if((i==1||j==m)&&a[i][j]==1) {
f2[i][j]=1; maxv=1;
}
else f2[i][j]=0;
}
for(int i=2;i<=n;i++)
for(int j=2;j<=m;j++){
if(a[i][j]==0) continue;
bool t=true;
for(int k=1;k<=f[i-1][j-1];k++){
if(a[i-k][j]==1||a[i][j-k]==1) {
t=false;
f[i][j]=k;
maxv=max(maxv,f[i][j]);
break;
}
}
if(t) {
f[i][j]=f[i-1][j-1]+1;
maxv=max(maxv,f[i][j]);
}
}
for(int i=2;i<=n;i++)
for(int j=m-1;j>=1;j--){
if(a[i][j]==0) continue;
bool t=true;
for(int k=1;k<=f2[i-1][j+1];k++){
if(a[i-k][j]==1||a[i][j+k]==1) {
t=false;
f[i][j]=k;maxv=max(maxv,f2[i][j]);
break;
}
}
if(t) {
f2[i][j]=f2[i-1][j+1]+1;
maxv=max(maxv,f2[i][j]);
}
}
cout<<maxv;
}