#include using namespace std; #define FOR(i,m,n) for(int i=(m);i<(n);++i) #define REP(i,n) FOR(i,0,n) using ll = long long; constexpr int INF = 0x3f3f3f3f; constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL; constexpr double EPS = 1e-8; constexpr int MOD = 998244353; // constexpr int MOD = 1000000007; constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1}; constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1}; constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1}; template inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; } template inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; } struct IOSetup { IOSetup() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << fixed << setprecision(20); } } iosetup; int main() { int h, w; cin >> h >> w; vector s(h); for (string& s_i : s) cin >> s_i; vector dp(h, vector(w, INF)); fill(dp.back().begin(), dp.back().end(), 0); for (int i = h - 2; i >= 0; --i) { vector l(w, w), r(w, -1); for (int j = 0, cur = -1; j < w; ++j) { if (s[i][j] == '#') { cur = j; } else { l[j] = cur + 1; } } for (int j = w - 1, cur = w; j >= 0; --j) { if (s[i][j] == '#') { cur = j; } else { r[j] = cur - 1; } } vector> ins(w), era(w); REP(j, w) { if (s[i][j] == '.') { ins[max(j - dp[i + 1][j], l[j])].emplace_back(dp[i + 1][j]); era[min(j + dp[i + 1][j], r[j])].emplace_back(dp[i + 1][j]); } } multiset st; REP(j, w) { for (const int x : ins[j]) st.emplace(x); if (s[i][j] == '.') dp[i][j] = *st.begin(); for (const int x : era[j]) st.erase(st.find(x)); } priority_queue, vector>, greater>> que; REP(j, w) { if (s[i][j] == '.') que.emplace(dp[i][j], j); } while (!que.empty()) { const auto [tmp, x] = que.top(); que.pop(); if (tmp > dp[i][x]) continue; if (x > 0 && s[i][x - 1] == '.' && chmin(dp[i][x - 1], dp[i][x] + 1)) que.emplace(dp[i][x - 1], x - 1); if (x + 1 < w && s[i][x + 1] == '.' && chmin(dp[i][x + 1], dp[i][x] + 1)) que.emplace(dp[i][x + 1], x + 1); } } REP(j, w) cout << dp.front()[j] << '\n'; // REP(i, h) REP(j, w) cout << dp[i][j] << " \n"[j + 1 == w]; return 0; }