#include //#include using namespace std; //using namespace atcoder; //using mint = modint998244353; //const int mod = 998244353; //using mint = modint1000000007; //const int mod = 1000000007; const int INF = 1e9; //const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } template struct DualSegtree { private: int mn = 0; int mN = 0; int mlogN = 0; std::vector A; void propagate(int i) { if (i >= mN) return; A[i * 2] = op(A[i * 2], A[i]); A[i * 2 + 1] = op(A[i * 2 + 1], A[i]); A[i] = e(); } void full_propagate(int i) { for (int d = mlogN; d > 0; d--) propagate(i >> d); } public: DualSegtree(int n = 0) { mn = n; mlogN = 0; mN = 1; while (mN < n) { mN *= 2; mlogN++; } A.assign(mN * 2, e()); } void point_init(int p) { assert(0 <= p); assert(p < mn); p += mN; full_propagate(p); A[p] = e(); } S get(int p) { assert(0 <= p); assert(p < mn); p += mN; full_propagate(p); return A[p]; } void apply(int l, int r, S x) { l += mN; r += mN; if (l != mN) full_propagate(l - 1); if (r != mN * 2) full_propagate(r); while (l < r) { if (l & 1) { A[l] = op(A[l], x); l++; } if (r & 1) { r--; A[r] = op(A[r], x); } l /= 2; r /= 2; } } }; //区間chmin、一点取得 using S = int; S op(S x, S f) { return std::min(x, f); } S e() { return { INF }; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, m; cin >> n >> m; vectors(n); rep(i, n)cin >> s[i]; reverse(all(s)); vector dp(n, vector(m, INF)); rep(i, m)if ('#' != s[0][i])dp[0][i] = 0; rep2(i, 1, n) { vectorlwall(m), rwall(m); lwall[0] = -1; rep(j, m) { if ('#' == s[i][j])lwall[j] = j; else if (0 != j)lwall[j] = lwall[j - 1]; } rwall[m - 1] = m; rrep(j, m) { if ('#' == s[i][j])rwall[j] = j; else if (j != m - 1)rwall[j] = rwall[j + 1]; } DualSegtreesegl(m), segm(m), segr(m); rep(j, m) { if ('#' == s[i - 1][j])continue; if ('#' == s[i][j])continue; { int l = lwall[j] + 1; int r = max(lwall[j] + 1, j - dp[i - 1][j]); if (l <= r) segl.apply(l, r, j); } { int l = max(lwall[j] + 1, j - dp[i - 1][j]); int r = min(rwall[j], j + dp[i - 1][j] + 1); if (l <= r) segm.apply(l, r, dp[i - 1][j]); } { int l = min(rwall[j], j + dp[i - 1][j] + 1); int r = rwall[j]; if (l <= r) segr.apply(l, r, -j); } } rep(j, m) { auto get = segl.get(j); if (INF != abs(get))chmin(dp[i][j], segl.get(j) - j); get = segm.get(j); if (INF != abs(get))chmin(dp[i][j], segm.get(j)); get = segr.get(j); if (INF != abs(get))chmin(dp[i][j], segr.get(j) + j); } } rep(j, m)cout << dp.back()[j] << endl; return 0; }