#include using namespace std; using ll = long long; #define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i) #define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i) #define all(x) begin(x), end(x) template bool chmax(T& a, const T& b) { return a < b ? (a = b, 1) : 0; } template bool chmin(T& a, const T& b) { return a > b ? (a = b, 1) : 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(15); int H, W; cin >> H >> W; vector S(H); for (auto& row : S) cin >> row; vector dp(W, 0); const int INF = 1e9; revrep(i, H, 0) { vector ndp(W, INF); vector> diff(W); multiset st; int left = -1; rep(j, 0, W) { if (S[i][j] == '#') { st.clear(); left = -1; continue; } st.insert(dp[j]); if (j + dp[j] < W) { diff[j + dp[j]].push_back(j); } if (!st.empty()) { chmin(ndp[j], *st.begin()); } if (left != -1) { chmin(ndp[j], j - left); } for (int k : diff[j]) { st.erase(st.find(dp[k])); chmax(left, k); } diff[j].clear(); } st.clear(); int right = W; revrep(j, W, 0) { if (S[i][j] == '#') { st.clear(); right = W; continue; } st.insert(dp[j]); if (j - dp[j] >= 0) { diff[j - dp[j]].push_back(j); } if (!st.empty()) { chmin(ndp[j], *st.begin()); } if (right != W) { chmin(ndp[j], right - j); } for (int k : diff[j]) { st.erase(st.find(dp[k])); chmin(right, k); } } dp.swap(ndp); } rep(j, 0, W) cout << dp[j] << "\n"; }