#line 2 "/Users/tiramister/CompetitiveProgramming/Cpp/CppLibrary/Tools/vector_alias.hpp" #include template std::vector vec(int len, T elem) { return std::vector(len, elem); } #line 2 "main.cpp" #include #line 5 "main.cpp" #include #include #include void solve() { int h, w; std::cin >> h >> w; std::vector ss(h); for (auto &s : ss) std::cin >> s; auto dist = vec(h, vec(w, -1)); std::queue> que; for (int x = -1; x <= h; ++x) { for (int y = -1; y <= w; ++y) { if (x < 0 || h <= x || y < 0 || w <= y) { que.emplace(0, x, y); } else if (ss[x][y] == '.') { dist[x][y] = 0; que.emplace(0, x, y); } } } while (!que.empty()) { auto [d, x, y] = que.front(); que.pop(); for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { int nx = x + dx, ny = y + dy; if (nx < 0 || h <= nx || ny < 0 || w <= ny || dist[nx][ny] != -1) continue; dist[nx][ny] = d + 1; que.emplace(dist[nx][ny], nx, ny); } } } int ans = 0; for (int x = 0; x < h; ++x) { for (int y = 0; y < w; ++y) { ans = std::max(ans, dist[x][y]); } } std::cout << ans << "\n"; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }