#include #include #include using namespace std; int main() { int H, W; cin >> H >> W; vector lsHW(H + 2, string(W + 2, '.')); for (int i = 1; i <= H; ++i) { string row; cin >> row; lsHW[i] = '.' + row + '.'; } H += 2; W += 2; const int INF = 5000; vector> cost(H, vector(W, INF)); vector> dxy = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}}; deque> d; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (lsHW[i][j] == '.') { cost[i][j] = 0; d.emplace_back(i, j); } } } int cmax = 0; while (!d.empty()) { int x = d.front().first; int y = d.front().second; d.pop_front(); for (const auto& dxdy : dxy) { int dx = dxdy.first; int dy = dxdy.second; if (0 <= x + dx && x + dx < H && 0 <= y + dy && y + dy < W) { if (cost[x + dx][y + dy] > cost[x][y] + 1) { cost[x + dx][y + dy] = cost[x][y] + 1; cmax = cost[x][y] + 1; d.emplace_back(x + dx, y + dy); } } } } cout << cmax << endl; return 0; }