#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int h,w; cin >> h >> w; vector S(h); for (auto &s: S) cin >> s; vector dp(w,0); const int INF = 1e9; for (int i = h-2; i >= 0; i--){ vector ndp(w,INF); vector>> event(w); for (int x = 0; x < w; x++){ int cost = dp[x]; event[max(0,x-cost)].push_back({cost,1}); } for (int x = 0; x < w; x++){ event[x].push_back({x,0}); } for (int x = 0; x < w; x++){ int cost = dp[x]; event[min(w-1,x+cost)].push_back({cost,-1}); } multiset ms; ms.insert(INF); for (int x = 0; x < w; x++){ for (auto [c,t] : event[x]){ if (t == 1) { ms.insert(c); } else if (t == 0){ if (S[i][c] == '#') continue; ndp[c] = *ms.begin(); } else{ auto it = ms.find(c); // イテレータがマルチセットの終端でない、つまり要素が見つかった場合、その要素を削除 if (it != ms.end()) { ms.erase(it); } else{ assert (0); } } } } for (int x = 1; x < w; x++){ ndp[x] = min(ndp[x],ndp[x-1]+1); } for (int x = w-2;x >= 0; x--){ ndp[x] = min(ndp[x],ndp[x+1]+1); } for (int x = 0;x < w; x++){ if (S[i][x] == '#'){ ndp[x] = INF; } if (i > 0 && S[i-1][x] != '.'){ ndp[x] = INF; } } swap(dp,ndp); } for (auto a: dp){ cout << a << endl; } return 0; }