Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = deque()
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            b.append([h, w, 0])

ans = 0
while len(b) > 0:
    h, w, d = b.popleft()
    for y, x in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = h + y, w + x
        if nh >= 0 and nh < H and nw >= 0 and nw < W and hw[nh][nw] == '.':
            b.append([nh, nw, d + 1])
            ans = max([ans, d + 1])
            hw[nh][nw] = "#"
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = deque()
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            b.append([h, w, 0])

ans = 0
while len(b) > 0:
    h, w, d = b.popleft()
    d += 1
    for y, x in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = h + y, w + x
        if nh >= 0 and nh < H and nw >= 0 and nw < W and hw[nh][nw] == '.':
            b.append([nh, nw, d])
            if ans < d:
                ans = d
            hw[nh][nw] = "#"
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = []
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            b.append([h, w, 0])

ans = 0
while len(b) > 0:
    h, w, d = b.pop(0)
    for y, x in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = h + y, w + x
        if nh >= 0 and nh < H and nw >= 0 and nw < W and hw[nh][nw] == '.':
            b.append([nh, nw, d + 1])
            ans = max([ans, d + 1])
            hw[nh][nw] = "#"
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = deque()
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            b.append([h, w, 0])

ans = 0
while len(b) > 0:
    h, w, d = b.popleft()
    d += 1
    for y, x in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = h + y, w + x
        if nh >= 0 and nh < H and nw >= 0 and nw < W and hw[nh][nw] == '.':
            b.append([nh, nw, d])
            if ans < d:
                ans = d
            hw[nh][nw] = "#"
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = []
e = []
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            hw[h][w] = 0
            b.append([h, w])
        else:
            hw[h][w] = 1001
            e.append([h, w])

ans = 0
for ey, ex in e:
    ta = 2**31
    for by, bx in b:
        d = abs(ey-by)+abs(ex-bx)
        if d < ta:
            ta = d
    if ta > ans:
        ans = ta
print(ans)


Fixed submission:
from collections import deque
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = deque()
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            b.append([h, w, 0])

ans = 0
while len(b) > 0:
    h, w, d = b.popleft()
    d += 1
    for y, x in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = h + y, w + x
        if nh >= 0 and nh < H and nw >= 0 and nw < W and hw[nh][nw] == '.':
            b.append([nh, nw, d])
            if ans < d:
                ans = d
            hw[nh][nw] = "#"
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = []
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            hw[h][w] = 0
            b.append([h, w])
        else:
            hw[h][w] = 1001

d = [[1, 0], [-1, 0], [0, 1], [0, -1]]
ans = 0
while len(b) > 0:
    h, w = b.pop(0)
    for y, x in d:
        nh, nw = h+y, w+x
        if nh >= 0 and nh < H and nw >= 0 and nw < W and hw[nh][nw] == 1001:
            hw[nh][nw] = hw[h][w]+1
            b.append([nh, nw])
            if hw[nh][nw] > ans:
                ans = hw[nh][nw]
print(ans)


Fixed submission:
from collections import deque
H, W = map(int, input().split())
hw = [list(input().strip()) for _ in range(H)]
b = deque()
for h in range(H):
    for w in range(W):
        if hw[h][w] == '#':
            b.append([h, w, 0])

ans = 0
while len(b) > 0:
    h, w, d = b.popleft()
    d += 1
    for y, x in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
        nh, nw = h + y, w + x
        if nh >= 0 and nh < H and nw >= 0 and nw < W and hw[nh][nw] == '.':
            b.append([nh, nw, d])
            if ans < d:
                ans = d
            hw[nh][nw] = "#"
print(ans)