Kdlyh @ 2019-02-08 21:49:22
#include <cstdio>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
const int N = 2500 + 10;
int n,m;
int g[N][N];
int s[N][N];
int l,r,mid,ans;
bool check(int x) {
for(re int i=x; i<=n; i++) {
for(re int j=x; j<=m; j++) {
if(g[i][j]) {
//printf("i=%d j=%d s=%d x=%d\n",i,j,s[i][j]-s[i-x][j]-s[i][j-x]+s[i-x][j-x],x);
if(s[i][j]-s[i-x][j]-s[i][j-x]+s[i-x][j-x] == x) {
for(re int k=1; k<x; ++k) {
if(!g[i-k][j-k]) {
break;
}
if(k == x-1) {
return true;
}
}
}
if(s[i][j]-s[i-x][j]-s[i][j+x]+s[i-x][j+x] == x) {
for(re int k=1; k<x; ++k) {
if(!g[i-k][j+k] || j+k > m) {
break;
}
if(k == x-1) {
return true;
}
}
}
}
}
}
return false;
}
void Input() {
scanf("%d%d",&n,&m);
for(re int i=1; i<=n; ++i) {
for(re int j=1; j<=m; ++j) {
scanf("%d",&g[i][j]);
s[i][j]=s[i][j-1]+s[i-1][j]-s[i-1][j-1]+g[i][j];
}
}
}
void Solve() {
l=1,r=min(n,m);
while(l <= r) {
mid=(l+r)>>1;
if(check(mid)) {
l=mid+1;
ans=mid;
} else {
r=mid-1;
}
}
printf("%d",ans);
}
int main(void) {
Input();
Solve();
return 0;
}
by herolxl @ 2019-04-13 08:58:51
。