Buggy python submission (verdict: Time Limit Exceeded):
import queue
import copy

H, W = map(int,input().split())
A = [input() for i in range(H)]
q1 = queue.Queue()
q2 = queue.Queue()
visit = [[False]*W for i in range(H)]
cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q1.put([i,j])
            visit[i][j] = True

while not q1.empty():
    while not q1.empty():
        index = q1.get()
        for i in [-1,1]:
            for j in [-1,1]:
                if index[0]+i >= 0 and index[0]+i < H:
                    if not visit[index[0]+i][index[1]]:
                        visit[index[0]+i][index[1]] = True
                        q2.put([index[0]+i,index[1]])
                if index[1]+j >= 0 and index[1]+j < W:
                    if not visit[index[0]][index[1]+j]:
                        visit[index[0]][index[1]+j] = True
                        q2.put([index[0],index[1]+j])
    q1.queue = copy.deepcopy(q2.queue)
    q2 = queue.Queue()
    cnt += 1
    
print(cnt-1)




Fixed submission:
H, W = map(int,input().split())
A = [input() for i in range(H)]
q1 = []
q2 = []
visit = [[False]*W for i in range(H)]
cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q1.append([i,j])
            visit[i][j] = True

while q1:
    while q1:
        index = q1.pop()
        for i in [-1,1]:
            for j in [-1,1]:
                if index[0]+i >= 0 and index[0]+i < H:
                    if not visit[index[0]+i][index[1]]:
                        visit[index[0]+i][index[1]] = True
                        q2.append([index[0]+i,index[1]])
                if index[1]+j >= 0 and index[1]+j < W:
                    if not visit[index[0]][index[1]+j]:
                        visit[index[0]][index[1]+j] = True
                        q2.append([index[0],index[1]+j])
    q1 = q2[:]
    q2 = []
    cnt += 1
    
print(cnt-1)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
import copy

H, W = map(int,input().split())
A = [input() for i in range(H)]
q1 = queue.Queue()
q2 = queue.Queue()
visit = [[False]*W for i in range(H)]
cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q1.put([i,j])
            visit[i][j] = True

while not q1.empty():
    while not q1.empty():
        index = q1.get()
        for i in [-1,1]:
            for j in [-1,1]:
                if index[0]+i >= 0 and index[0]+i < H:
                    if not visit[index[0]+i][index[1]]:
                        visit[index[0]+i][index[1]] = True
                        q2.put([index[0]+i,index[1]])
                if index[1]+j >= 0 and index[1]+j < W:
                    if not visit[index[0]][index[1]+j]:
                        visit[index[0]][index[1]+j] = True
                        q2.put([index[0],index[1]+j])
    q1.queue = copy.deepcopy(q2.queue)
    q2 = queue.Queue()
    cnt += 1
    
print(cnt-1)




Fixed submission:
H, W = map(int,input().split())
A = [input() for i in range(H)]
q1 = []
q2 = []
visit = [[False]*W for i in range(H)]
cnt = 0

for i in range(H):
    for j in range(W):
        if A[i][j] == "#":
            q1.append([i,j])
            visit[i][j] = True

while q1:
    while q1:
        index = q1.pop()
        for i in [-1,1]:
            for j in [-1,1]:
                if index[0]+i >= 0 and index[0]+i < H:
                    if not visit[index[0]+i][index[1]]:
                        visit[index[0]+i][index[1]] = True
                        q2.append([index[0]+i,index[1]])
                if index[1]+j >= 0 and index[1]+j < W:
                    if not visit[index[0]][index[1]+j]:
                        visit[index[0]][index[1]+j] = True
                        q2.append([index[0],index[1]+j])
    q1 = q2[:]
    q2 = []
    cnt += 1
    
print(cnt-1)