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

H,W = map(int,input().split())
INFTY = 10000
q = []
A = np.array([[(q.append((i,j)) or 0) if c=="#" else INFTY 
               for j,c in enumerate(input())] + [0] for i in range(H)]
             +[[0]*(W+1)])

ans = -1
while q:
    qq = []
    for i,j in q:
        v = A[i,j]+1
        if A[i,j+1] > v:
            A[i,j+1] = v
            qq.append((i,j+1))
        if A[i,j-1] > v:
            A[i,j-1] = v
            qq.append((i,j-1))
        if A[i+1,j] > v:
            A[i+1,j] = v
            qq.append((i+1,j))
        if A[i-1,j] > v:
            A[i-1,j] = A[i,j]+1
            qq.append((i-1,j))
    q = qq
    ans += 1

print(ans)

Fixed submission:
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

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

H,W = list(map(int,input().split()))
INFTY = 10000
A = np.array([[0 if c=="#" else INFTY for c in input()]for _ in range(H)] )

for i in range(H):
    A[:-1] = np.min((A[:-1],A[1:]+1),0)
    A[1:] = np.min((A[1:],A[:-1]+1),0)
A=A.T
for i in range(W):
    A[:-1] = np.min((A[:-1],A[1:]+1),0)
    A[1:] = np.min((A[1:],A[:-1]+1),0)
print(np.max(A))

Fixed submission:
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

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

H,W = list(map(int,input().split()))
INFTY = 10000
A = np.array([[0 if c=="#" else INFTY for c in input()]for _ in range(H)] )

for i in range(H+W):
    A[:-1] = np.min((A[:-1],A[1:]+1),0)
    A[1:] = np.min((A[1:],A[:-1]+1),0)
    A[:,:-1] = np.min((A[:,:-1],A[:,1:]+1),0)
    A[:,1:] = np.min((A[:,1:],A[:,:-1]+1),0)
print(np.max(A))

Fixed submission:
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

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

H,W = list(map(int,input().split()))
INFTY = 10000
A = np.array([[-1]*(W+2)] + 
             [[-1]+[0 if c=="#" else INFTY for c in input()] + [-1] 
              for _ in range(H)] + 
             [[-1]*(W+2)] )

q = []
for i in range(1,H+1):
    for j in range(1,W+1):
        if A[i][j] == 0:
            q.append((i,j))
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if A[i-1][j]==INFTY:
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if A[i+1][j]==INFTY:
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if A[i][j-1]==INFTY:
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if A[i][j+1]==INFTY:
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

Fixed submission:
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

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

H,W = list(map(int,input().split()))
INFTY = 10000
A = np.array([[0 if c=="#" else INFTY for c in input()] for _ in range(H)])

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == 0:
            q.append((i,j))
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==INFTY:
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==INFTY:
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==INFTY:
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==INFTY:
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

Fixed submission:
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)

Fixed submission:
H,W = list(map(int,input().split()))
A = [list(input()) for _ in range(H)]

q = []
for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q.append((i,j))
            A[i][j] = 0
ans = 0
k = 0
while k < len(q):
    i,j = q[k]
    v = A[i][j]
    if i>0 and A[i-1][j]==".":
        A[i-1][j] = v + 1
        q.append((i-1,j))
        ans = max(ans,v+1)
    if i<H-1 and A[i+1][j]==".":
        A[i+1][j] = v + 1
        q.append((i+1,j))
        ans = max(ans,v+1)
    if j>0 and A[i][j-1]==".":
        A[i][j-1] = v + 1
        q.append((i,j-1))
        ans = max(ans,v+1)
    if j<W-1 and A[i][j+1]==".":
        A[i][j+1] = v + 1
        q.append((i,j+1))
        ans = max(ans,v+1)
    k += 1
print(ans)