Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def inside(x, l, r):
    return l <= x < r


H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
qu = deque()

rest = H * W
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            rest -= 1
            qu.append((i, j))

ans = 0
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
while True:
    if rest == 0:
        break
    ans += 1
    qu2 = deque()
    while qu:
        i0, j0 = qu.popleft()
        for k in range(4):
            ni = i0 + dx[k]
            nj = j0 + dy[k]
            if not (inside(ni, 0, H) and inside(nj, 0, W)):
                continue
            if A[ni][nj] == '.':
                A[ni][nj] = '#'
                rest -= 1
                qu2.append((ni, nj))
    qu = qu2
print(ans)



Fixed submission:
# 参考

import numpy

H, W = map(int, input().split())
values = [None] * H

for y in range(H):
    values[y] = [0 if v == "#" else H + W for v in input()]
values = numpy.array(values)

for x in range(W - 1):
    values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

for x in range(W - 1, 0, -1):
    values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

for y in range(H - 1):
    values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

for y in range(H - 1, 0, -1):
    values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

print(numpy.max(values))

Buggy python submission (verdict: Runtime Error):
from collections import deque


def inside(x, l, r):
    return l <= x < r


H, W = map(int, input().split())
A = [list(input()) for i in range(H)]
qu = deque()

rest = H * W
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            rest -= 1
            qu.put((i, j))

ans = 0
dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]
while True:
    if rest == 0:
        break
    ans += 1
    qu2 = deque()
    while qu:
        i0, j0 = qu.get()
        for k in range(4):
            ni = i0 + dx[k]
            nj = j0 + dy[k]
            if not (inside(ni, 0, H) and inside(nj, 0, W)):
                continue
            if A[ni][nj] == '.':
                A[ni][nj] = '#'
                rest -= 1
                qu2.put((ni, nj))
    qu = qu2
print(ans)


Fixed submission:
# 参考

import numpy

H, W = map(int, input().split())
values = [None] * H

for y in range(H):
    values[y] = [0 if v == "#" else H + W for v in input()]
values = numpy.array(values)

for x in range(W - 1):
    values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

for x in range(W - 1, 0, -1):
    values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

for y in range(H - 1):
    values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

for y in range(H - 1, 0, -1):
    values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

print(numpy.max(values))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
A = [input() for _ in range(H)]

blacks = []
for h in range(H):
    count = A[h].count("#")
    w = -1
    nw = 0
    for c in range(count):
        w = A[h][(w+1):].find("#")
        nw += w
        blacks.append((h, nw))

max_dist = 0
for h in range(H):
    for w in range(W):
        if (h, w) in blacks:
            continue

        min_d = H + W
        for (i, j) in blacks:
            cm = abs(h - i) + abs(w - j)
            if cm < min_d:
                min_d = cm
        if min_d > max_dist:
            max_dist = min_d

print(max_dist)



Fixed submission:
# 参考

import numpy

H, W = map(int, input().split())
values = [None] * H

for y in range(H):
    values[y] = [0 if v == "#" else H + W for v in input()]
values = numpy.array(values)

for x in range(W - 1):
    values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

for x in range(W - 1, 0, -1):
    values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

for y in range(H - 1):
    values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

for y in range(H - 1, 0, -1):
    values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

print(numpy.max(values))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
A = [input() for _ in range(H)]

blacks = []
for h in range(H):
     for w in range(W):
         if A[h][w] == "#":
             blacks.append((h, w))

max_dist = 0
for h in range(H):
    for w in range(W):
        min_d = H+W
        for (i, j) in blacks:
            cm = abs(h - i) + abs(w - j)
            if cm < min_d:
                min_d = cm
        if min_d > max_dist:
            max_dist = min_d

print(max_dist)

Fixed submission:
# 参考

import numpy

H, W = map(int, input().split())
values = [None] * H

for y in range(H):
    values[y] = [0 if v == "#" else H + W for v in input()]
values = numpy.array(values)

for x in range(W - 1):
    values[:, x + 1] = numpy.minimum(values[:, x] + 1, values[:, x + 1])

for x in range(W - 1, 0, -1):
    values[:, x - 1] = numpy.minimum(values[:, x] + 1, values[:, x - 1])

for y in range(H - 1):
    values[y + 1, :] = numpy.minimum(values[y, :] + 1, values[y + 1, :])

for y in range(H - 1, 0, -1):
    values[y - 1, :] = numpy.minimum(values[y, :] + 1, values[y - 1, :])

print(numpy.max(values))