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

H,W = map(int, input().split())
maze = [input() for _ in range(H)]
visited = [[False]*W for _ in range(H)]
q = deque([])

# initialize
for h in range(H):
    for w in range(W):
        if maze[h][w] == "#":
            q.append((h,w,0))
            visited[h][w] = True

ans = 0
while q:
    h,w,d = q.popleft()
    for dy,dx in zip([0,0,-1,1], [-1,1,0,0]):
        nh, nw = h+dy, w+dx
        if not(0<=nh<H and 0<=nw<W):
            continue
        if not visited[nh][nw]:
            q.append((nh,nw,d+1))
            visited[nh][nw] = True
            ans = max(ans, d+1)

print(ans)


Fixed submission:
from collections import deque

H,W = map(int, input().split())
maze = [input() for _ in range(H)]
visited = [[False]*W for _ in range(H)]
q = deque([])

# initialize
for h in range(H):
    for w in range(W):
        if maze[h][w] == "#":
            q.append((h,w,0))
            visited[h][w] = True

ans = 0
while q:
    h,w,d = q.popleft()
    for dy,dx in zip([0,0,-1,1], [-1,1,0,0]):
        nh, nw = h+dy, w+dx
        if not(0<=nh<H and 0<=nw<W):
            continue
        if not visited[nh][nw]:
            q.append((nh,nw,d+1))
            visited[nh][nw] = True
            ans = max(ans, d+1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H,W = map(int, input().split())
maze = [input() for _ in range(H)]
dist = [[None]*W for _ in range(H)]

stack = deque([])
for h in range(H):
    for w in range(W):
        if maze[h][w]=="#":
            stack.append((h,w))
            dist[h][w] = 0

ans = 0
while stack:
    ch,cw = stack.popleft()
    ans = max(ans, dist[ch][cw])
    for y,x in zip([0,0,-1,1], [1,-1,0,0]):
        nh,nw = ch+y, cw+x
        if not(0 <= nh < H and 0 <= nw < W):
            continue
        if dist[nh][nw] == None:
            stack.append((nh,nw))
            dist[nh][nw] = dist[ch][cw] + 1
        else:
            dist[nh][nw] = min(dist[nh][nw], dist[ch][cw] + 1)

print(ans)
# print(*dist, sep="\n")


Fixed submission:
from collections import deque

H,W = map(int, input().split())
maze = [input() for _ in range(H)]
visited = [[False]*W for _ in range(H)]
q = deque([])

# initialize
for h in range(H):
    for w in range(W):
        if maze[h][w] == "#":
            q.append((h,w,0))
            visited[h][w] = True

ans = 0
while q:
    h,w,d = q.popleft()
    for dy,dx in zip([0,0,-1,1], [-1,1,0,0]):
        nh, nw = h+dy, w+dx
        if not(0<=nh<H and 0<=nw<W):
            continue
        if not visited[nh][nw]:
            q.append((nh,nw,d+1))
            visited[nh][nw] = True
            ans = max(ans, d+1)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W = map(int, input().split())
black,white = [],[]

for h in range(H):
    a = input()
    for w in range(W):
        if a[w]=="#":
            black.append((h,w))
        else:
            white.append((h,w))

ans = 0
for wh,ww in white:
    tmp = float("inf")
    for bh,bw in black:
        if tmp > abs(wh-bh) + abs(ww-bw):
            tmp =  abs(wh-bh) + abs(ww-bw)
    ans = max(ans, tmp)
print(ans)


Fixed submission:
from collections import deque

H,W = map(int, input().split())
maze = [input() for _ in range(H)]
visited = [[False]*W for _ in range(H)]
q = deque([])

# initialize
for h in range(H):
    for w in range(W):
        if maze[h][w] == "#":
            q.append((h,w,0))
            visited[h][w] = True

ans = 0
while q:
    h,w,d = q.popleft()
    for dy,dx in zip([0,0,-1,1], [-1,1,0,0]):
        nh, nw = h+dy, w+dx
        if not(0<=nh<H and 0<=nw<W):
            continue
        if not visited[nh][nw]:
            q.append((nh,nw,d+1))
            visited[nh][nw] = True
            ans = max(ans, d+1)

print(ans)