import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } string COLOR(string s = "") { return "\x1b[" ~ s ~ "m"; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } class MinPQue(T) { BinaryHeap!(Array!T, "a > b") que0, que1; int size() { return cast(int)(que0.length) - cast(int)(que1.length); } void push(T t) { que0.insert(t); } void erase(T t) { que1.insert(t); } void reduce() { for (; que0.length && que1.length && que0.front == que1.front; que0.removeFront, que1.removeFront) {} } T top() { reduce; return que0.front; } void pop() { reduce; que0.front; } } enum INF = 1001001001; void main() { try { for (; ; ) { const M = readInt; const N = readInt; auto S = new string[](M, N); foreach (x; 0 .. M) { S[x] = readToken; } auto addss = new int[][N + 1]; auto remss = new int[][N + 1]; auto dp = new int[N]; foreach_reverse (x; 0 .. M - 1) { for (int y0 = 0, y1; y0 < N; y0 = y1) { for (y1 = y0; y1 < N && S[x][y0] == S[x][y1]; ++y1) {} if (S[x][y0] == '.') { foreach (y; y0 .. y1 + 1) { addss[y] = []; remss[y] = []; } foreach (y; y0 .. y1) if (dp[y] < INF) { // free const yL = max(y0, y - dp[y]); const yR = min(y1, y + dp[y] + 1); addss[yL] ~= dp[y]; remss[yR] ~= dp[y]; } auto que = new MinPQue!int; foreach (y; y0 .. y1) { foreach (f; addss[y]) que.push(f); foreach (f; remss[y]) que.erase(f); dp[y] = que.size ? que.top : INF; } foreach (y; y0 .. y1 - 1) chmin(dp[y + 1], dp[y] + 1); foreach_reverse (y; y0 + 1 .. y1) chmin(dp[y - 1], dp[y] + 1); } else { dp[y0 .. y1] = INF; } } debug { writeln(dp); } } foreach (y; 0 .. N) { writeln(dp[y]); } } } catch (EOFException e) { } }