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

H, W = map(int, input().split())
A = []
checked = []
black = []
INF = 10**9
for i in range(H):
    tmp = input()
    A.append(tmp)
    checked.append([0 if tmp[j] == '#' else INF for j in range(W)])
    black += [(i, j) for j in range(W) if checked[-1][j] == 0]
black = deque(black)
ans = 0
while black:
    i, j = black.popleft()
    d = checked[i][j]
    ans = max(ans, d)
    if i > 0 and checked[i-1][j] == INF:
        checked[i-1][j] = d+1
        black.append((i-1, j))
    if i < H-1 and checked[i+1][j] == INF:
        checked[i+1][j] = d+1
        black.append((i+1, j))
    if j > 0 and checked[i][j-1] == INF:
        checked[i][j-1] = d+1
        black.append((i, j-1))
    if j < W-1 and checked[i][j+1] == INF:
        checked[i][j+1] = d+1
        black.append((i, j+1))
print(ans)

Fixed submission:
import numpy as np
from itertools import product
from collections import deque

H, W = map(int, input().split())
val = []
INF = 10**9
for i in range(H):
    tmp = input()
    val.append([0 if tmp[j] == '#' else INF for j in range(W)])
val = np.array(val)

for i in range(H-1):
    val[i+1, :] = np.minimum(val[i, :]+1, val[i+1, :])
for i in range(H-1, 0, -1):
    val[i-1, :] = np.minimum(val[i, :]+1, val[i-1, :])
for j in range(W-1):
    val[:, j+1] = np.minimum(val[:, j]+1, val[:, j+1])
for j in range(W-1, 0, -1):
    val[:, j-1] = np.minimum(val[:, j]+1, val[:, j-1])

print(val.max())

Buggy python submission (verdict: Runtime Error):
from itertools import product
from collections import deque

H, W = map(int, input().split())
A = []
checked = []
black = []
INF = 10**9
for i in range(H):
    tmp = input()
    A.append(tmp)
    checked.append([0 if tmp[j] == '#' else INF for j in range(W)])
    black += [((i, j), 0) for j in range(W) if checked[-1][j] == 0]
black = deque(black)
ans = 0
while black:
    (i, j), d = black.popleft()
    ans = max(ans, d)
    if i > 0:
        checked[i-1][j] = min(checked[i-1][j], d+1)
        black.append((i-1, j), checked[i-1][j])
    if i < H-1:
        checked[i+1][j] = min(checked[i+1][j], d+1)
        black.append((i+1, j), checked[i+1][j])
    if j > 0:
        checked[i][j-1] = min(checked[i][j-1], d+1)
        black.append((i, j-1), checked[i][j-1])
    if j < W-1:
        checked[i][j+1] = min(checked[i][j+1], d+1)
        black.append((i, j+1), checked[i][j+1])
print(ans)

Fixed submission:
import numpy as np
from itertools import product
from collections import deque

H, W = map(int, input().split())
val = []
INF = 10**9
for i in range(H):
    tmp = input()
    val.append([0 if tmp[j] == '#' else INF for j in range(W)])
val = np.array(val)

for i in range(H-1):
    val[i+1, :] = np.minimum(val[i, :]+1, val[i+1, :])
for i in range(H-1, 0, -1):
    val[i-1, :] = np.minimum(val[i, :]+1, val[i-1, :])
for j in range(W-1):
    val[:, j+1] = np.minimum(val[:, j]+1, val[:, j+1])
for j in range(W-1, 0, -1):
    val[:, j-1] = np.minimum(val[:, j]+1, val[:, j-1])

print(val.max())

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

H, W = map(int, input().split())
A = []
checked = []
black = []
for i in range(H):
    tmp = input()
    A.append(tmp)
    checked.append([tmp[j] == '#' for j in range(W)])
    black += [((i, j), 0) for j in range(W) if checked[-1][j]]
black = deque(black)
ans = 0
while black:
    (i, j), d = black.popleft()
    ans = max(ans, d)
    if i > 0 and not checked[i-1][j]:
        checked[i-1][j] = True
        black.append(((i-1, j), d+1))
    if i < H-1 and not checked[i+1][j]:
        checked[i+1][j] = True
        black.append(((i+1, j), d+1))
    if j > 0 and not checked[i][j-1]:
        checked[i][j-1] = True
        black.append(((i, j-1), d+1))
    if j < W-1 and not checked[i][j+1]:
        checked[i][j+1] = True
        black.append(((i, j+1), d+1))
print(ans)

Fixed submission:
import numpy as np
from itertools import product
from collections import deque

H, W = map(int, input().split())
val = []
INF = 10**9
for i in range(H):
    tmp = input()
    val.append([0 if tmp[j] == '#' else INF for j in range(W)])
val = np.array(val)

for i in range(H-1):
    val[i+1, :] = np.minimum(val[i, :]+1, val[i+1, :])
for i in range(H-1, 0, -1):
    val[i-1, :] = np.minimum(val[i, :]+1, val[i-1, :])
for j in range(W-1):
    val[:, j+1] = np.minimum(val[:, j]+1, val[:, j+1])
for j in range(W-1, 0, -1):
    val[:, j-1] = np.minimum(val[:, j]+1, val[:, j-1])

print(val.max())

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product
import scipy.spatial as ss

H, W = map(int, input().split())
A = []
black = []
for i in range(H):
    tmp = input()
    A.append(tmp)
    black += [(i, j) for j in range(W) if tmp[j] == '#']
ans = 0
tree = ss.KDTree(black, leafsize=10)
for i, j in product(range(H), range(W)):
    if A[i][j] == '.':
        dist_nn_bl = int(tree.query((i,j), k=1, p=1)[0])
        ans = max(ans, dist_nn_bl)
print(ans)

Fixed submission:
import numpy as np
from itertools import product
from collections import deque

H, W = map(int, input().split())
val = []
INF = 10**9
for i in range(H):
    tmp = input()
    val.append([0 if tmp[j] == '#' else INF for j in range(W)])
val = np.array(val)

for i in range(H-1):
    val[i+1, :] = np.minimum(val[i, :]+1, val[i+1, :])
for i in range(H-1, 0, -1):
    val[i-1, :] = np.minimum(val[i, :]+1, val[i-1, :])
for j in range(W-1):
    val[:, j+1] = np.minimum(val[:, j]+1, val[:, j+1])
for j in range(W-1, 0, -1):
    val[:, j-1] = np.minimum(val[:, j]+1, val[:, j-1])

print(val.max())

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

H, W = map(int, input().split())
A = []
black = []
for i in range(H):
    tmp = input()
    A.append(tmp)
    black += [(i, j) for j in range(W) if tmp[j] == '#']
ans = 0
for i, j in product(range(H), range(W)):
    if A[i][j] == '.':
        dist_bl = min([abs(b[0] - i) + abs(b[1] - j) for b in black])
        ans = max(ans, dist_bl)
print(ans)

Fixed submission:
import numpy as np
from itertools import product
from collections import deque

H, W = map(int, input().split())
val = []
INF = 10**9
for i in range(H):
    tmp = input()
    val.append([0 if tmp[j] == '#' else INF for j in range(W)])
val = np.array(val)

for i in range(H-1):
    val[i+1, :] = np.minimum(val[i, :]+1, val[i+1, :])
for i in range(H-1, 0, -1):
    val[i-1, :] = np.minimum(val[i, :]+1, val[i-1, :])
for j in range(W-1):
    val[:, j+1] = np.minimum(val[:, j]+1, val[:, j+1])
for j in range(W-1, 0, -1):
    val[:, j-1] = np.minimum(val[:, j]+1, val[:, j-1])

print(val.max())