Buggy python submission (verdict: Time Limit Exceeded):
import sys
H, W, *A = sys.stdin.read().split()
H = int(H); W = int(W)

rW = range(W)
rrW = range(W-1, -1, -1)
rH = range(H)

INF = 2000
dist = [[INF]*W for i in rH]
for di, Ai in zip(dist, A):
    for j, a in enumerate(Ai):
        if a == '#':
            di[j] = 0
for di in dist:
    cur = INF
    for j in rW:
        if not di[j]:
            cur = -j
        else:
            di[j] = cur+j
    cur = INF
    for j in rrW:
        if not di[j]:
            cur = j
        elif cur-j < di[j]:
            di[j] = cur-j
for j in rW:
    cur = INF
    for di in dist:
        if cur+1 < di[j]:
            di[j] = cur = cur+1
        else:
            cur = di[j]
    cur = INF
    for di in reversed(dist):
        if cur+1 < di[j]:
            di[j] = cur = cur+1
        else:
            cur = di[j]
sys.stdout.write("%d\n" % max(max(di) for di in dist))

Fixed submission:
from collections import deque

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

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
H, W, *A = sys.stdin.read().split()
H = int(H); W = int(W)

INF = 8000
dist = [[INF]*(W) for i in range(H)]
for i in range(H):
    di = dist[i]
    Ai = A[i]
    for j, a in enumerate(Ai):
        if a == '#':
            di[j] = 0
for i in range(H):
    cur = INF
    di = dist[i]
    for j in range(W):
        if di[j] == 0:
            cur = 0
        else:
            di[j] = cur = cur+1
    cur = INF
    for j in range(W-1, -1, -1):
        if di[j] == 0:
            cur = 0
        else:
            di[j] = cur = min(di[j], cur+1)
for j in range(W):
    cur = INF
    for di in dist:
        if cur+1 < di[j]:
            di[j] = cur = cur+1
        else:
            cur = di[j]
    cur = INF
    for di in reversed(dist):
        if cur+1 < di[j]:
            di[j] = cur = cur+1
        else:
            cur = di[j]
sys.stdout.write("%d\n" % max(max(di) for di in dist))

Fixed submission:
from collections import deque

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

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
H, W, *A = sys.stdin.read().split()
H = int(H); W = int(W)

INF = 8000
dist = [[INF]*(W+1) for i in range(H+1)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
que = []
for i in range(H):
    di = dist[i]
    Ai = A[i]
    for j, a in enumerate(Ai):
        if a == '#':
            di[j] = 0
for i in range(H):
    cur = INF
    di = dist[i]
    for j in range(W):
        di[j] = cur = min(cur+1, di[j])
    cur = INF
    for j in range(W-1, -1, -1):
        di[j] = cur = min(cur+1, di[j])
for j in range(W):
    cur = INF
    for i in range(H):
        dist[i][j] = cur = min(cur+1, dist[i][j])
    cur = INF
    for i in range(H-1, -1, -1):
        dist[i][j] = cur = min(cur+1, dist[i][j])
ans = 0
for i in range(H):
    di = dist[i]
    for j in range(W):
        ans = max(ans, di[j])
sys.stdout.write("%d\n" % ans)

Fixed submission:
from collections import deque

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

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H, W = map(int, readline().split())
A = [readline() for i in range(H)]

dist = [[0]*(W+1) for i in range(H+1)]
for i in range(H):
    dist[i][W] = 1
for i in range(W):
    dist[H][i] = 1
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
que = []
push = que.append
for i in range(H):
    di = dist[i]
    Ai = A[i]
    for j in range(W):
        if Ai[j] == '#':
            di[j] = 1
            push((i, j))

d = 0
que1 = []
push1 = que1.append
while que:
    for dx, dy in dd:
        for y, x in que:
            nx = x + dx; ny = y + dy
            if dist[ny][nx]:
                continue
            dist[ny][nx] = 1
            push1((ny, nx))
    que.clear()
    que, que1 = que1, que
    push, push1 = push1, push
    d += 1
sys.stdout.write("%d\n" % (d-1))

Fixed submission:
from collections import deque

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

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
readline = sys.stdin.readline

H, W = map(int, readline().split())
A = [readline() for i in range(H)]

dist = [[0]*(W+1) for i in range(H+1)]
for i in range(H):
    dist[i][W] = 1
for i in range(W):
    dist[H][i] = 1
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
que = []
push = que.append
for i in range(H):
    di = dist[i]
    Ai = A[i]
    for j in range(W):
        if Ai[j] == '#':
            di[j] = 1
            push((i, j))

d = 0
que1 = []
while que:
    push = que1.append
    for y, x in que:
        for dx, dy in dd:
            nx = x + dx; ny = y + dy
            if dist[ny][nx]:
                continue
            dist[ny][nx] = 1
            push((ny, nx))
    que.clear()
    que, que1 = que1, que
    d += 1
sys.stdout.write("%d\n" % (d-1))

Fixed submission:
from collections import deque

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

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)

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

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

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)

Fixed submission:
from collections import deque

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

dist = [[-1]*W for i in range(H)]
dd = ((-1, 0), (0, -1), (1, 0), (0, 1))
for i in range(H):
    for j in range(W):
        if A[i][j] == '#':
            dist[i][j] = 0
            que.append((i, j))

d = 0
while que:
    y, x = que.popleft()
    d = dist[y][x]
    for dx, dy in dd:
        nx = x + dx; ny = y + dy
        if not 0 <= nx < W or not 0 <= ny < H or dist[ny][nx] != -1:
            continue
        dist[ny][nx] = d+1
        que.append((ny, nx))
print(d)