#include #include using namespace std; struct State { int row, col, dist; State(int row, int col, int dist) : row(row), col(col), dist(dist) { } }; const int kINF = 1 << 28; const int kMAX_H = 3100; const int kMAX_W = 3100; string S[kMAX_H]; int dist[kMAX_H][kMAX_W]; int H, W; bool IsIn(int row, int col) { return 0 <= row && row < H && 0 <= col && col < W; } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> H >> W; for (int r = 0; r < H; r++) { cin >> S[r]; } queue que; fill((int* )dist, (int* )(dist + kMAX_H), kINF); for (int r = 0; r < H; r++) { for (int c = 0; c < W; c++) { if (S[r][c] == '.') { que.push(State(r, c, 0)); dist[r][c] = 0; } } } while (!que.empty()) { State s = que.front(); que.pop(); for (int dr = -1; dr <= 1; dr++) { for (int dc = -1; dc <= 1; dc++) { int nr = s.row + dr, nc = s.col + dc; if (IsIn(nr, nc) && S[nr][nc] == '#' && dist[nr][nc] == kINF) { que.push(State(nr, nc, s.dist + 1)); dist[nr][nc] = s.dist + 1; } } } } int ans = 0; for (int r = 0; r < H; r++) { for (int c = 0; c < W; c++) { if (S[r][c] == '.') continue; /* if (S[r][c] == '.') { cout << "x "; continue; } */ int move_r = min(r, H - 1 - r) + 1, move_c = min(c, W - 1 - c) + 1, c_dist = min(move_r, move_c); ans = max(ans, min(dist[r][c], c_dist)); // cout << min(dist[r][c], c_dist) << " "; } // cout << endl; } cout << ans << endl; return 0; }