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

h, w = map(int, input().split())
used = [[False] * (w+2) for _ in range(h+2)]
for r in range(h+2):
    used[r][0] = True
    used[r][-1] = True
for c in range(w+2):
    used[0][c] = True
    used[-1][c] = True
que = deque([])
for r in range(h):
    line = input()
    for c in range(w):
        if line[c] == "#":
            que.append((r+1, c+1, 0))
            used[r+1][c+1] = 0
neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
while que:
    r, c, k = que.popleft()
    for dr, dc in neighbors:
        nr, nc = r+dr, c+dc
        if not used[nr][nc]:
            que.append((nr, nc, k+1))
            used[nr][nc] = True
print(k)


Fixed submission:
from collections import deque

def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

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

h, w = map(int, input().split())
used = [[False] * (w+2) for _ in range(h+2)]
for r in range(h+2):
    used[r][0] = True
    used[r][-1] = True
for c in range(w+2):
    used[0][c] = True
    used[-1][c] = True
que = deque([])
for r in range(h):
    line = input()
    for c in range(w):
        if line[c] == "#":
            que.append((r+1, c+1, 0))
            used[r+1][c+1] = 0
neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
while que:
    r, c, k = que.popleft()
    for dr, dc in neighbors:
        nr, nc = r+dr, c+dc
        if not used[nr][nc]:
            que.append((nr, nc, k+1))
            used[nr][nc] = True
print(k)

Fixed submission:
from collections import deque

def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

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

def solve(h, w, a):
    used = [[False] * (w+2) for _ in range(h+2)]
    for r in range(h+2):
        used[r][0] = True
        used[r][-1] = True
    for c in range(w+2):
        used[0][c] = True
        used[-1][c] = True
    que = deque([])
    for r in range(h):
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
                used[r+1][c+1] = 0
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

Fixed submission:
from collections import deque

def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

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

def solve(h, w, a):
    used = [[False] * (w+2) for _ in range(h+2)]
    for r in range(h+2):
        used[r][0] = True
        used[r][-1] = True
    for c in range(w+2):
        used[0][c] = True
        used[-1][c] = True
    que = deque([])
    for r in range(h):
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
                used[r+1][c+1] = 0
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

Fixed submission:
from collections import deque

def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))

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

def solve(h, w, a): 
    dist = np.full((h, w), -1, dtype=int)
    que = deque([])
    for r in range(h):
        for c in range(w):
            if a[r][c] == "#":
                que.append((r, c, 0)) 
                dist[r, c] = 0 
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if (0 <= nr < h) and (0 <= nc < w) and (dist[nr, nc] == -1):
                que.append((nr, nc, k+1))
                dist[nr, nc] = k+1 
    return np.max(dist)

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a)) 

Fixed submission:
from collections import deque

def solve(h, w, a):
    used = [[True] * (w+2) for _ in range(h+2)]
    que = deque()
    for r in range(h):
        used[r+1][1:-1] = map(lambda _:_=="#", a[r])
        for c in range(w):
            if a[r][c] == "#":
                que.append((r+1, c+1, 0))
    neighbors = [(1,0), (0,1), (-1,0), (0,-1)]
    while que:
        r, c, k = que.popleft()
        for dr, dc in neighbors:
            nr, nc = r+dr, c+dc
            if not used[nr][nc]:
                que.append((nr, nc, k+1))
                used[nr][nc] = True
    return k

h, w = map(int, input().split())
a = [input() for _ in range(h)]
print(solve(h, w, a))