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

def main():
    h,w = map(int,input().split())
    q = []
    A = ["" for i in range(h)]
    for i in range(h):
        b = input()
        A[i] = b
    #    print(b)
        for j in range(w):
            if b[j]=="#": q.append([i,j,0])
    #print(A)
    while q:
        a,b,c = q.pop(0)
        for x,y in [(1,0),(0,1),(-1,0),(0,-1)]:
            if 0<=b+y<h and 0<=a+x<w and A[b+y][a+x] == ".":
                #print(b+y,a+x)
                q.append([b+y,a+x,c+1])
                l = list(A[b+y])
                l[a+x] = "#"
                A[b+y] = "".join(l)
        if not q:
            print(c)
            break
    #print(A)
if __name__ == '__main__':
    main()



Fixed submission:
import numpy as np
def main():
    h,w = map(int, input().split())
    mat = []
    for i in range(h):
        b = input()
        mat.append([0 if j=="#" else h+w for j in b])
    arr = np.array(mat)

    for i in range(w-1):
        arr[:,i+1] = np.minimum(arr[:,i]+1,arr[:,i+1])
        #print(arr)

    for i in range(w-1,0,-1):
        arr[:,i-1] = np.minimum(arr[:,i]+1,arr[:,i-1])
        #print(arr)

    for i in range(h-1):
        arr[i+1,:] = np.minimum(arr[i,:]+1,arr[i+1,:])
        #print(arr)

    for i in range(h-1,0,-1):
        arr[i-1,:] = np.minimum(arr[i,:]+1, arr[i-1,:])
        #print(arr)
    print(np.max(arr))


if __name__ == '__main__' :
    main()

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

def main():
    h,w = map(int,input().split())
    q = []
    A = ["" for i in range(h)]
    for i in range(h):
        b = input()
        A[i] = b
    #    print(b)
        for j in range(w):
            if b[j]=="#": q.append([i,j,0])
    #print(A)
    while q:
        a,b,c = q.pop(0)
        for x,y in [(1,0),(0,1),(-1,0),(0,-1)]:
            if 0<=b+y<h and 0<=a+x<w and A[b+y][a+x] == ".":
                #print(b+y,a+x)
                q.append([b+y,a+x,c+1])
                l = list(A[b+y])
                l[a+x] = "#"
                A[b+y] = "".join(l)
        if not q:
            print(c)
            break
    #print(A)
if __name__ == '__main__':
    main()



Fixed submission:
import numpy as np
def main():
    h,w = map(int, input().split())
    mat = []
    for i in range(h):
        b = input()
        mat.append([0 if j=="#" else h+w for j in b])
    arr = np.array(mat)

    for i in range(w-1):
        arr[:,i+1] = np.minimum(arr[:,i]+1,arr[:,i+1])
        #print(arr)

    for i in range(w-1,0,-1):
        arr[:,i-1] = np.minimum(arr[:,i]+1,arr[:,i-1])
        #print(arr)

    for i in range(h-1):
        arr[i+1,:] = np.minimum(arr[i,:]+1,arr[i+1,:])
        #print(arr)

    for i in range(h-1,0,-1):
        arr[i-1,:] = np.minimum(arr[i,:]+1, arr[i-1,:])
        #print(arr)
    print(np.max(arr))


if __name__ == '__main__' :
    main()

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

def main():
    h,w = map(int,input().split())
    q = queue.Queue()
    A = ["" for i in range(h)]
    for i in range(h):
        b = input()
        A[i] = b
    #    print(b)
        for j in range(w):
            if b[j]=="#": q.put([i,j,0])
    #print(A)
    while not q.empty():
        a,b,c = q.get()
        for x,y in [(1,0),(0,1),(-1,0),(0,-1)]:
            if 0<=b+y<h and 0<=a+x<w and A[b+y][a+x] == ".":
                #print(b+y,a+x)
                q.put([b+y,a+x,c+1])
                l = list(A[b+y])
                l[a+x] = "#"
                A[b+y] = "".join(l)
        if q.empty():
            print(c)
            break
    #print(A)
if __name__ == '__main__':
    main()



Fixed submission:
import numpy as np
def main():
    h,w = map(int, input().split())
    mat = []
    for i in range(h):
        b = input()
        mat.append([0 if j=="#" else h+w for j in b])
    arr = np.array(mat)

    for i in range(w-1):
        arr[:,i+1] = np.minimum(arr[:,i]+1,arr[:,i+1])
        #print(arr)

    for i in range(w-1,0,-1):
        arr[:,i-1] = np.minimum(arr[:,i]+1,arr[:,i-1])
        #print(arr)

    for i in range(h-1):
        arr[i+1,:] = np.minimum(arr[i,:]+1,arr[i+1,:])
        #print(arr)

    for i in range(h-1,0,-1):
        arr[i-1,:] = np.minimum(arr[i,:]+1, arr[i-1,:])
        #print(arr)
    print(np.max(arr))


if __name__ == '__main__' :
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import queue
h,w = map(int,input().split())
q = queue.Queue()
A = ["" for i in range(h)]
for i in range(h):
    b = input()
    A[i] = b
#    print(b)
    for j in range(w):
        if b[j]=="#": q.put([i,j,0])
#print(A)
while not q.empty():
    a,b,c = q.get()
    for x,y in [(1,0),(0,1),(-1,0),(0,-1)]:
        if 0<=b+y<h and 0<=a+x<w and A[b+y][a+x] == ".":
            #print(b+y,a+x)
            q.put([b+y,a+x,c+1])
            l = list(A[b+y])
            l[a+x] = "#"
            A[b+y] = "".join(l)
    if q.empty():
        print(c)
        break
#print(A)




Fixed submission:
import numpy as np
def main():
    h,w = map(int, input().split())
    mat = []
    for i in range(h):
        b = input()
        mat.append([0 if j=="#" else h+w for j in b])
    arr = np.array(mat)

    for i in range(w-1):
        arr[:,i+1] = np.minimum(arr[:,i]+1,arr[:,i+1])
        #print(arr)

    for i in range(w-1,0,-1):
        arr[:,i-1] = np.minimum(arr[:,i]+1,arr[:,i-1])
        #print(arr)

    for i in range(h-1):
        arr[i+1,:] = np.minimum(arr[i,:]+1,arr[i+1,:])
        #print(arr)

    for i in range(h-1,0,-1):
        arr[i-1,:] = np.minimum(arr[i,:]+1, arr[i-1,:])
        #print(arr)
    print(np.max(arr))


if __name__ == '__main__' :
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import queue
h,w = map(int,input().split())
q = queue.Queue()
A = ["" for i in range(h)]
for i in range(h):
    b = input()
    A[i] = b
#    print(b)
    for j in range(w):
        if b[j]=="#": q.put([i,j,0])
#print(A)
while not q.empty():
    a,b,c = q.get()
    for x,y in [(1,0),(0,1),(-1,0),(0,-1)]:
        if 0<=b+y<h and 0<=a+x<w and A[b+y][a+x] == ".":
            #print(b+y,a+x)
            q.put([b+y,a+x,c+1])
            l = list(A[b+y])
            l[a+x] = "#"
            A[b+y] = "".join(l)
    if q.empty():
        print(c)
        break
#print(A)




Fixed submission:
import numpy as np
def main():
    h,w = map(int, input().split())
    mat = []
    for i in range(h):
        b = input()
        mat.append([0 if j=="#" else h+w for j in b])
    arr = np.array(mat)

    for i in range(w-1):
        arr[:,i+1] = np.minimum(arr[:,i]+1,arr[:,i+1])
        #print(arr)

    for i in range(w-1,0,-1):
        arr[:,i-1] = np.minimum(arr[:,i]+1,arr[:,i-1])
        #print(arr)

    for i in range(h-1):
        arr[i+1,:] = np.minimum(arr[i,:]+1,arr[i+1,:])
        #print(arr)

    for i in range(h-1,0,-1):
        arr[i-1,:] = np.minimum(arr[i,:]+1, arr[i-1,:])
        #print(arr)
    print(np.max(arr))


if __name__ == '__main__' :
    main()