Buggy python submission (verdict: Time Limit Exceeded):
#import time 

H, W = map(int, input().split())

status = [10000]*H*W
targets = set()
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            targets.add((i, j))
            status[i*W+j] = 0

#t2 = time.time()
#c = 0
while True:
    #print("---")
    #for s_i in range(H):
    #    print(status[s_i*W:(s_i+1)*W])
    #print(targets)
    try:
        i, j = targets.pop()
    except KeyError:
        break
    
    d = status[i*W+j] + 1
    
    left = i*W+j-1
    if j != 0 and status[left] > d:
        status[left] = d # left
        targets.add((i, j-1))

    right = i*W+j+1
    if j != W-1 and status[right] > d:
        status[right] = d # right
        targets.add((i, j+1))

    up = (i-1)*W+j
    if i != 0 and status[up] > d:
        status[up] = d # up
        targets.add((i-1, j))

    down = (i+1)*W+j
    if i != H-1 and status[down] > d:
        status[down] = d # down
        targets.add((i+1, j))
    
    # c += 1
#t3 = time.time()

#print("count", c)
print(max(status))
#print(t3 - t2)

Fixed submission:
import numpy as np

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))

Buggy python submission (verdict: Time Limit Exceeded):
#import time 

H, W = map(int, input().split())

status = [10000]*H*W
targets = set()
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            targets.add((i, j))
            status[i*W+j] = 0

#t2 = time.time()
#c = 0
while True:
    #print("---")
    #for s_i in range(H):
    #    print(status[s_i*W:(s_i+1)*W])
    #print(targets)
    try:
        i, j = targets.pop()
    except KeyError:
        break
    
    d = status[i*W+j] + 1
    
    left = i*W+j-1
    if j != 0 and status[left] > d:
        status[left] = d # left
        targets.add((i, j-1))

    right = i*W+j+1
    if j != W-1 and status[right] > d:
        status[right] = d # right
        targets.add((i, j+1))

    up = (i-1)*W+j
    if i != 0 and status[up] > d:
        status[up] = d # up
        targets.add((i-1, j))

    down = (i+1)*W+j
    if i != H-1 and status[down] > d:
        status[down] = d # down
        targets.add((i+1, j))
    
    # c += 1
#t3 = time.time()

#print("count", c)
print(max(status))
#print(t3 - t2)

Fixed submission:
import numpy as np

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))

Buggy python submission (verdict: Time Limit Exceeded):
# import time 

H, W = map(int, input().split())

#t1 = time.time()

status = [10000]*H*W
targets = []
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            targets.append((i, j))
            status[i*W+j] = 0

#t2 = time.time()
#c = 0
while True:
    #print("---")
    #for s_i in range(H):
    #    print(status[s_i*W:(s_i+1)*W])
    #print(targets)
    try:
        i, j = targets.pop(0)
    except IndexError:
        break
    
    d = status[i*W+j] + 1
    
    if j != 0 and status[i*W+j-1] > d:
        status[i*W+j-1] = min(status[i*W+j-1], d) # left
        targets.append((i, j-1))

    if j != W-1 and status[i*W+j+1] > d:
        status[i*W+j+1] = min(status[i*W+j+1], d) # right
        targets.append((i, j+1))

    if i != 0 and status[(i-1)*W+j] > d:
        status[(i-1)*W+j] = min(status[(i-1)*W+j], d) # up
        targets.append((i-1, j))

    if i != H-1 and status[(i+1)*W+j] > d:
        status[(i+1)*W+j] = min(status[(i+1)*W+j], d) # down
        targets.append((i+1, j))
    
#   c += 1
#t3 = time.time()

#print("count", c)
print(max(status))
#print(t2 - t1, t3 - t2)

Fixed submission:
import numpy as np

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

status = [10000]*H*W
targets = set()
for i in range(H):
    s = input()
    for j, s_j in enumerate(s):
        if s_j == "#":
            targets.add((i, j))
            status[i*W+j] = 0

#c = 0
while True:
    #print("---")
    #for s_i in range(H):
    #    print(status[s_i*W:(s_i+1)*W])
    #print(targets)
    try:
        i, j = targets.pop()
    except KeyError:
        break
    
    d = status[i*W+j] + 1
    
    if j != 0 and status[i*W+j-1] > d:
        status[i*W+j-1] = min(status[i*W+j-1], d) # left
        targets.add((i, j-1))

    if j != W-1 and status[i*W+j+1] > d:
        status[i*W+j+1] = min(status[i*W+j+1], d) # right
        targets.add((i, j+1))

    if i != 0 and status[(i-1)*W+j] > d:
        status[(i-1)*W+j] = min(status[(i-1)*W+j], d) # up
        targets.add((i-1, j))

    if i != H-1 and status[(i+1)*W+j] > d:
        status[(i+1)*W+j] = min(status[(i+1)*W+j], d) # down
        targets.add((i+1, j))
    
 #   c += 1

#print("count", c)
print(max(status))


Fixed submission:
import numpy as np

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
 
status = [10000]*H*W
targets = []
for i in range(H):
    s = input()
    for j, s_j in enumerate(s):
        if s_j == "#":
            targets.append((i, j))
            status[i*W+j] = 0
 
while True:
    try:
        i, j = targets.pop(0)
    except IndexError:
        break
    
    d = status[i*W+j] + 1
    
    if j != 0 and status[i*W+j-1] > d:
        status[i*W+j-1] = min(status[i*W+j-1], d) # left
        targets.append((i, j-1))
 
    if j != W-1 and status[i*W+j+1] > d:
        status[i*W+j+1] = min(status[i*W+j+1], d) # right
        targets.append((i, j+1))
 
    if i != 0 and status[(i-1)*W+j] > d:
        status[(i-1)*W+j] = min(status[(i-1)*W+j], d) # up
        targets.append((i-1, j))
 
    if i != H-1 and status[(i+1)*W+j] > d:
        status[(i+1)*W+j] = min(status[(i+1)*W+j], d) # down
        targets.append((i+1, j))
 
 
print(max(status))

Fixed submission:
import numpy as np

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())

status = [10000]*H*W
targets = []
for i in range(H):
    s = input()
    for j, s_j in enumerate(s):
        if s_j == "#":
            targets.append((i, j))
            status[i*W+j] = 0

while True:
    try:
        i, j = targets.pop()
    except IndexError:
        break
    
    d = status[i*W+j] + 1
    
    if j != 0 and status[i*W+j-1] > d:
        status[i*W+j-1] = min(status[i*W+j-1], d) # left
        targets.append((i, j-1))

    if j != W-1 and status[i*W+j+1] > d:
        status[i*W+j+1] = min(status[i*W+j+1], d) # right
        targets.append((i, j+1))

    if i != 0 and status[(i-1)*W+j] > d:
        status[(i-1)*W+j] = min(status[(i-1)*W+j], d) # up
        targets.append((i-1, j))

    if i != H-1 and status[(i+1)*W+j] > d:
        status[(i+1)*W+j] = min(status[(i+1)*W+j], d) # down
        targets.append((i+1, j))


print(max(status))


Fixed submission:
import numpy as np

H, W = map(int, input().split())

status = np.full((H, W), H*W, dtype=int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == "#":
            status[i,j] = 0

for h in range(1, H):
    status[h, :] = np.minimum(status[h, :], status[h-1, :] + 1)
for h in range(0, H-1)[::-1]:
    status[h, :] = np.minimum(status[h, :], status[h+1, :] + 1)
for w in range(1, W):
    status[:, w] = np.minimum(status[:, w], status[:, w-1] + 1)
for w in range(0, W-1)[::-1]:
    status[:, w] = np.minimum(status[:, w], status[:, w+1] + 1)

print(np.max(status))