Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
q = deque()
grid = [[10**6] * W for _ in range(H)]
dire = ((1,0),(0,1),(-1,0),(0,-1))
d = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            grid[i][j] = 0
 
while q:
    i, j = q.popleft()
    d = grid[i][j]
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] > grid[i][j]:
            q.append((ny, nx))
            grid[ny][nx] = grid[i][j] + 1
 
print(d)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for _ in range(H)]
q = deque([])
grid = [[-1] * W for _ in range(H)]
dire = ((1,0),(0,1),(-1,0),(0,-1))
d = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            grid[i][j] = 0
 
while q:
    i, j = q.popleft()
    d = grid[i][j]
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] < 0:
            q.append((ny, nx))
            grid[ny][nx] = grid[i][j] + 1
 
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int, input().split())
a = [list(input()) for _ in range(H)]
q = deque()
inf_ = float("inf")
grid = [[inf_] * W for _ in range(H)]
dire = ((1,0),(0,1),(-1,0),(0,-1))
d = 0
 
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            q.append([i,j])
            grid[i][j] = 0
 
while q:
    i, j = q.popleft()
    d = max(d,grid[i][j]) 
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] > grid[i][j]:
            q.append([ny, nx])
            grid[ny][nx] = grid[i][j] + 1
 
print(d)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for _ in range(H)]
q = deque([])
grid = [[-1] * W for _ in range(H)]
dire = ((1,0),(0,1),(-1,0),(0,-1))
d = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            grid[i][j] = 0
 
while q:
    i, j = q.popleft()
    d = grid[i][j]
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] < 0:
            q.append((ny, nx))
            grid[ny][nx] = grid[i][j] + 1
 
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
inf_ = float("inf")
grid = [[inf_] * W for _ in range(H)]
stack = []
dire = [(1,0),(0,1),(-1,0),(0,-1)]
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            stack.append([i,j,0])
while stack:
    i, j, now = stack.pop()
    grid[i][j] = now
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] > now+1:
            stack.append([ny,nx,now+1])
for g in grid:
    ans = max(ans,max(g))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for _ in range(H)]
q = deque([])
grid = [[-1] * W for _ in range(H)]
dire = ((1,0),(0,1),(-1,0),(0,-1))
d = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            grid[i][j] = 0
 
while q:
    i, j = q.popleft()
    d = grid[i][j]
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] < 0:
            q.append((ny, nx))
            grid[ny][nx] = grid[i][j] + 1
 
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
A = [list(input()) for _ in range(H)]
inf_ = float("inf")
grid = [[inf_] * W for _ in range(H)]
stack = []
dire = [(1,0),(0,1),(-1,0),(0,-1)]
ans = 0
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            stack.append([i,j,0])
while stack:
    i, j, now = stack.pop()
    grid[i][j] = now
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] > now+1:
            stack.append([ny,nx,now+1])
for g in grid:
    ans = max(ans,max(g))
print(ans)

Fixed submission:
from collections import deque
H, W = map(int, input().split())
A = [input() for _ in range(H)]
q = deque([])
grid = [[-1] * W for _ in range(H)]
dire = ((1,0),(0,1),(-1,0),(0,-1))
d = 0
 
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            grid[i][j] = 0
 
while q:
    i, j = q.popleft()
    d = grid[i][j]
    for dy, dx in dire:
        ny,nx = i+dy, j+dx
        if ny>=0 and ny<H and nx>=0 and nx<W and grid[ny][nx] < 0:
            q.append((ny, nx))
            grid[ny][nx] = grid[i][j] + 1
 
print(d)