Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w = map(int,input().split())
grid = [['']*w for i in range(h)]
que = deque([])
d = [[float('inf')]*w for i in range(h)]
for i in range(h):
    temp = list(input())
    grid[i] = temp
    for j in range(w):
        if temp[j] == '#':
            d[i][j] = 0
            que.append([i,j])
dx = [0,-1,0,1]
dy = [-1,0,1,0]
ans = 0
while que:
    [px,py] = que.popleft()
    for i in range(4):
        nx = px + dx[i]
        ny = py + dy[i]
        if 0<=nx<h and 0<=ny<w and d[nx][ny] == float('inf') and grid[nx][ny] == '.':
            d[nx][ny] = d[px][py] + 1
            ans = d[nx][ny]
            que.append([nx,ny])
print(ans)

Fixed submission:
from collections import deque
h,w = map(int,input().split())
a = []
d = []
que = deque()
for i in range(h):
    a.append(list(input()))
    d.append([1e100]*w)
    for j in range(w):
        if a[i][j] == '#':
            que.append([i,j])
            d[i][j] = 0
di = [-1,0,1,0]
dj = [0,1,0,-1]
ans = 0

while que:
    i,j = que.popleft()
    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if 0 <= ni < h and 0 <= nj < w and d[ni][nj] == 1e100:
            d[ni][nj] = d[i][j] + 1
            ans = max(ans, d[ni][nj])
            que.append([ni,nj])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w = map(int,input().split())
grid = [list(input()) for i in range(h)]
que = deque([])
d = [[float('inf')]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            d[i][j] = 0
            que.append([i,j])
dx = [0,-1,0,1]
dy = [-1,0,1,0]
ans = 0
while que:
    [px,py] = que.popleft()
    for i in range(4):
        nx = px + dx[i]
        ny = py + dy[i]
        if 0<=nx<h and 0<=ny<w and grid[nx][ny] == '.' and d[nx][ny] == float('inf'):
            d[nx][ny] = d[px][py] + 1
            ans = d[nx][ny]
            que.append([nx,ny])
print(ans)


Fixed submission:
from collections import deque
h,w = map(int,input().split())
a = []
d = []
que = deque()
for i in range(h):
    a.append(list(input()))
    d.append([1e100]*w)
    for j in range(w):
        if a[i][j] == '#':
            que.append([i,j])
            d[i][j] = 0
di = [-1,0,1,0]
dj = [0,1,0,-1]
ans = 0

while que:
    i,j = que.popleft()
    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if 0 <= ni < h and 0 <= nj < w and d[ni][nj] == 1e100:
            d[ni][nj] = d[i][j] + 1
            ans = max(ans, d[ni][nj])
            que.append([ni,nj])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h,w = map(int,input().split())
grid = [list(input()) for i in range(h)]
que = deque([])
d = [[float('inf')]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if grid[i][j] == '#':
            d[i][j] = 0
            que.append([i,j])
dx = [0,-1,0,1]
dy = [-1,0,1,0]
ans = 0
while que:
    [px,py] = que.popleft()
    for i in range(4):
        nx = px + dx[i]
        ny = py + dy[i]
        if 0<=nx<h and 0<=ny<w and grid[nx][ny] == '.' and d[nx][ny] == float('inf'):
            d[nx][ny] = d[px][py] + 1
            ans = max(d[nx][ny],ans)
            que.append([nx,ny])
print(ans)

Fixed submission:
from collections import deque
h,w = map(int,input().split())
a = []
d = []
que = deque()
for i in range(h):
    a.append(list(input()))
    d.append([1e100]*w)
    for j in range(w):
        if a[i][j] == '#':
            que.append([i,j])
            d[i][j] = 0
di = [-1,0,1,0]
dj = [0,1,0,-1]
ans = 0

while que:
    i,j = que.popleft()
    for k in range(4):
        ni = i + di[k]
        nj = j + dj[k]
        if 0 <= ni < h and 0 <= nj < w and d[ni][nj] == 1e100:
            d[ni][nj] = d[i][j] + 1
            ans = max(ans, d[ni][nj])
            que.append([ni,nj])
print(ans)