#include #include #include #include #include #include #include using namespace std; const int INF = 1000000; char b[3010][3010]; int d[3010][3010]; int dx[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dy[8] = { -1, -1, 0, 1, 1, 1, 0, -1 }; struct P { int x, y; }; int main() { cin.tie(0); ios::sync_with_stdio(false); int H, W; cin >> H >> W; fill((int*)begin(d), (int*)end(d), INF); queue

q; for(int i = 0; i < H + 2; i++) { for(int j = 0; j < W + 2; j++) { if(i != 0 && i != H + 1 && j != 0 && j != W + 1) { cin >> b[i][j]; } else { b[i][j] = '.'; } if(b[i][j] == '.') { d[i][j] = 0; q.push(P{ j, i }); } } } int ans = 0; while(!q.empty()) { P p = q.front(); q.pop(); for(int i = 0; i < 8; i++) { int ny = p.y + dy[i], nx = p.x + dx[i]; if(1 <= nx && nx <= W && 1 <= ny && ny <= H && d[p.y][p.x] + 1 < d[ny][nx]) { d[ny][nx] = d[p.y][p.x] + 1; q.push(P{ nx, ny }); ans = max(ans, d[ny][nx]); } } } cout << ans << endl; }