gjh303987897 @ 2020-01-15 23:22:37
#include<iostream>
#include<cstdio>
#include<algorithm>
#define maxn 2505
#define rk register
using namespace std;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch>'9'||ch<'0'){
if(ch=='-') f=-1;
ch=getchar();
}
while(ch<='9'&&ch>='0'){
x=(x<<3)+(x<<1)+(ch^48);
ch=getchar();
}
return x*f;
}
int dp1[maxn][maxn];
int dp2[maxn][maxn];
int dis[maxn][maxn];
int ans1,ans2;
int n,m;
int main()
{
n=read(); m=read();
for(rk int i=1;i<=n;i++){
for(rk int j=1;j<=m;j++){
int f=read();
if(f==1) dis[i][j]=1;
if(f==0) dis[i][j]=0;
}
}
for(register int i=0;i<=n;i++){
for(register int j=0;j<=m;j++){
if(dis[i+1][j+1]==0){
dp1[i+1][j+1]=0; ans1=max(ans1,dp1[i][j]);
}else{
dp1[i+1][j+1]=dp1[i][j]+1; ans1=max(ans1,dp1[i+1][j+1]);
}
}
}
for(register int i=n+1;i>=0;i--){
for(register int j=0;j<=m;j++){
if(dis[i-1][j+1]==0){
dp2[i-1][j+1]=0; ans2=max(ans2,dp2[i][j]);
}else{
dp2[i-1][j+1]=dp2[i][j]+1; ans2=max(ans2,dp2[i-1][j+1]);
}
}
}
cout<<max(ans1,ans2);
return 0;
}
by xukh @ 2020-02-15 15:22:11
如果某个正方形子矩阵的某条对角线上都有鱼,且此正方形子矩阵的其他地方无鱼