汪鸣谦 @ 2019-08-05 21:43:44
#include<bits/stdc++.h>
using namespace std;
int m,n;
int a[2501][2501],f[2501][2501]={0},g[2501][2501]={0};
int ans=-1e9;
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>a[i][j];
f[i][j]=a[i][j];
g[i][j]=a[i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(a[i][j]==1){
f[i][j]=f[i-1][j-1]+1;
for(int k=i-1;k>=i-f[i-1][j-1];k--){
if(a[k][j]==1){
f[i][j]=1;
break;
}
}
for(int k=j-1;k>=j-f[i-1][j-1];k--){
if(a[i][k]==1){
f[i][j]=1;
break;
}
}
}
//cout<<f[i][j]<<" ";
//if(f[i][j]>ans)ans=f[i][j];
}
//cout<<endl;
}
for(int i=1;i<=n;i++){
for(int j=m;j>=1;j--){
if(a[i][j]==1){
g[i][j]=g[i-1][j+1]+1;
for(int k=i-1;k>=i-g[i-1][j+1];k--){
if(a[k][j]==1){
g[i][j]=1;
break;
}
}
for(int k=j+1;k<=j+g[i-1][j+1];k++){
if(a[i][k]==1){
g[i][j]=1;
break;
}
}
}
//cout<<f[i][j]<<" ";
//if(f[i][j]>ans)ans=f[i][j];
}
//cout<<endl;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
//cout<<f[i][j]<<" ";
if(f[i][j]>ans){
ans=f[i][j];
}
}
//cout<<endl;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
//cout<<g[i][j]<<" ";
if(g[i][j]>ans){
ans=g[i][j];
}
}
//cout<<endl;
}
cout<<ans;
return 0;
}
by 汪鸣谦 @ 2019-08-05 21:44:07
帮查错谢啦