#include #define FL(i,a,b) for(int i=(a);i<=(b);i++) #define FR(i,a,b) for(int i=(a);i>=(b);i--) #define ll long long #define PII pair using namespace std; const int MAXN = 3e3 + 10; const int inf = 0x3f3f3f3f; int dx[8]={0,1,0,-1,1,1,-1,-1}; int dy[8]={1,0,-1,0,-1,1,1,-1}; char c[MAXN][MAXN]; int dis[MAXN][MAXN]; int main(){ // freopen("rufuge.in","r",stdin); // freopen("refuge.out","w",stdout); int H,W; scanf("%d%d",&H,&W); FL(i,1,H) FL(j,1,W) scanf(" %c",&c[i][j]); memset(dis,0x3f,sizeof(dis)); queueq; FL(i,0,H+1){ FL(j,0,W+1){ if(i<1||i>H||j<1||j>W||c[i][j]=='.') dis[i][j]=0,q.push({i,j}); } } int ans=0; while(!q.empty()){ PII u=q.front(); q.pop(); // printf("(%d,%d) %d\n",u.first,u.second,dis[u.first][u.second]); ans=max(ans,dis[u.first][u.second]); FL(i,0,7){ int x=u.first+dx[i],y=u.second+dy[i]; if(x<1||x>H||y<1||y>W) continue; if(dis[x][y]>dis[u.first][u.second]+1) dis[x][y]=dis[u.first][u.second]+1,q.push({x,y}); } } // FL(i,0,H+1){ // FL(j,0,W+1) printf("%d ",dis[i][j]); // puts(""); // } printf("%d\n",ans); }