#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) #define all(c) (c).begin(), (c).end() #define zero(a) memset(a, 0, sizeof a) #define minus(a) memset(a, -1, sizeof a) #define watch(a) { cout << #a << " = " << a << endl; } template inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); } template inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); } typedef long long ll; int const inf = 1<<29; int dx[4] = {-1,0,1,0}; int dy[4] = {0,-1,0,1}; template constexpr bool in_range(T y, T x, T H, T W) { return 0<=y&&y> H >> W; vector G(H + 2, string(W + 2, '.')); rep(i, H) rep(j, W) { scanf("%c", &G[i+1][j+1]); } H += 2, W += 2; priority_queue> q; vector> dist(H, vector(W, inf)); rep(i, H) rep(j, W) { if(G[i][j] == '.') { q.push({0, i, j, i, j}); dist[i][j] = 0; } } while(!q.empty()) { int c, y, x, sy, sx; tie(c, y, x, sy, sx) = q.top(); q.pop(); rep(k, 4) { int ny = y + dy[k], nx = x + dx[k]; if(!in_range(ny, nx, H, W)) continue; if(G[ny][nx] == '.') { if(dist[ny][nx] == 0) continue; dist[ny][nx] = 0; q.push({0, ny, nx, sy, sx}); } else if(dist[ny][nx] > max(abs(ny - sy), abs(nx - sx))) { dist[ny][nx] = max(abs(ny - sy), abs(nx - sx)); q.push({dist[ny][nx], ny, nx, sy, sx}); } } } int max = 0; rep(i, H) rep(j, W) { maximize(max, dist[i][j]); } cout << max << endl; return 0; }