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

H, W = map(int, input().split())
A_arr = []
que = deque()
dist = [[-1 for i in range(W)] for i in range(H)]

for i in range(H):
    A_arr.append(list(input()))
    for j in range(W):
        if A_arr[i][j] == "#":
            que.append([i,j])
            dist[i][j] = 0

n_list = [[1, 0], [-1, 0], [0, 1], [0, -1]]

while 1:
    if len(que) == 0:
        break
    
    x, y = que.popleft()
    d = dist[x][y]
    for n in range(4):
        tmp = [x + n_list[n][0], y + n_list[n][1]]
        if tmp[0] < 0 or tmp[0] >= H:
            pass
        elif tmp[1] < 0 or tmp[1] >= W:
            pass
        elif dist[tmp[0]][tmp[1]] != -1:
            pass
        else:
            dist[tmp[0]][tmp[1]] = d + 1
            que.append([tmp[0], tmp[1]])


print(d)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
A_arr = []
que = deque()
dist = [[-1 for i in range(W)] for i in range(H)]

for i in range(H):
    A_arr.append(list(input()))
    for j in range(W):
        if A_arr[i][j] == "#":
            que.append([i,j])
            dist[i][j] = 0

n_list = [[1, 0], [-1, 0], [0, 1], [0, -1]]

while 1:
    if len(que) == 0:
        break
    
    x, y = que.popleft()
    d = dist[x][y]
    for n in range(4):
        tmp = [x + n_list[n][0], y + n_list[n][1]]
        if tmp[0] < 0 or tmp[0] >= H:
            pass
        elif tmp[1] < 0 or tmp[1] >= W:
            pass
        elif dist[tmp[0]][tmp[1]] != -1:
            pass
        else:
            dist[tmp[0]][tmp[1]] = d + 1
            que.append([tmp[0], tmp[1]])


print(d)

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

for i in range(H):
    A_arr.append(list(input()))
    for j in range(W):
        if A_arr[i][j] == "#":
            s_arr1.append([i,j])


n_list = [[1, 0], [-1, 0], [0, 1], [0, -1]]
count = 0

while 1:
    if len(s_arr1) == H*W:
        break

    count += 1
    for i in range(len(s_arr1)):
        for n in range(4):
            tmp = [s_arr1[i][0] + n_list[n][0], s_arr1[i][1] + n_list[n][1]]
            if tmp[0] < 0 or tmp[0] >= H:
                pass
            elif tmp[1] < 0 or tmp[1] >= W:
                pass
            elif tmp in s_arr1:
                pass
            else:
                s_arr1.append(tmp)

    if len(s_arr1) == H*W:
        break

print(count)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
A_arr = []
que = deque()
dist = [[-1 for i in range(W)] for i in range(H)]

for i in range(H):
    A_arr.append(list(input()))
    for j in range(W):
        if A_arr[i][j] == "#":
            que.append([i,j])
            dist[i][j] = 0

n_list = [[1, 0], [-1, 0], [0, 1], [0, -1]]

while 1:
    if len(que) == 0:
        break
    
    x, y = que.popleft()
    d = dist[x][y]
    for n in range(4):
        tmp = [x + n_list[n][0], y + n_list[n][1]]
        if tmp[0] < 0 or tmp[0] >= H:
            pass
        elif tmp[1] < 0 or tmp[1] >= W:
            pass
        elif dist[tmp[0]][tmp[1]] != -1:
            pass
        else:
            dist[tmp[0]][tmp[1]] = d + 1
            que.append([tmp[0], tmp[1]])


print(d)