Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
H, W = map(int,input().split())
grid = [list(input()) for _ in range(H)]
w_cnt = 0
for i in range(H):
    w_cnt += grid[i].count('.')


d = [[-1]*W for _ in range(H)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]


que = deque()
for x in range(W):
    for y in range(H):
        if grid[y][x] == '#':
            d[y][x] = 0
            que.append([x,y])

while len(que) != 0:
    p = que.popleft()
    for i in range(4):
        nx = p[0] + dx[i]
        ny = p[1] + dy[i]
        #print(nx,ny)
        if 0 <= nx <= W-1 and 0 <= ny <= H-1 and grid[ny][nx] == '.' and d[ny][nx] == -1:
            que.append([nx,ny])
            d[ny][nx] = d[p[1]][p[0]] + 1

# print(d)
# print(d[H-1][W-1])
res = 0
for x in range(W):
    for y in range(H):
        res = max(res,d[y][x])
print(res)


Fixed submission:
from collections import deque
H, W = map(int,input().split())
grid = [list(input()) for _ in range(H)]


d = [[-1]*W for _ in range(H)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]


que = deque()
for x in range(W):
    for y in range(H):
        if grid[y][x] == '#':
            d[y][x] = 0
            que.append([x,y])

while len(que) != 0:
    p = que.popleft()
    for i in range(4):
        nx = p[0] + dx[i]
        ny = p[1] + dy[i]
        #print(nx,ny)
        if 0 <= nx <= W-1 and 0 <= ny <= H-1 and grid[ny][nx] == '.' and d[ny][nx] == -1:
            que.append([nx,ny])
            d[ny][nx] = d[p[1]][p[0]] + 1

# print(d)
# print(d[H-1][W-1])
res = 0
for x in range(W):
    for y in range(H):
        res = max(res,d[y][x])
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
def input():
    return sys.stdin.readline()[:-1]
h, w = map(int,input().split())
grid = np.array([list(input()) for _ in range(h)])

large_grid = np.array([["." for _ in range(w+2)] for _ in range(h+2)])
goal_grid = [["#" for _ in range(w)] for _ in range(h)]
cnt = 0

for i in range(1000):
    if (grid == goal_grid).all():
        print(cnt)
        break
    for row in range(h):
        for col in range(w):
            if grid[row][col] == "#":
                large_grid[row][col+1] = "#"
                large_grid[row+2][col+1] = "#"
                large_grid[row+1][col+1] = "#"
                large_grid[row+1][col+2] = "#"
                large_grid[row+1][col] = "#"

    grid3 = large_grid[1:h+1, 1:w+1]
    #grid = grid3#参照元とかの問題でバグる
    grid = np.copy(grid3)
    cnt +=1

#     grid = grid2
#     print(grid2)
#     print(grid)








Fixed submission:
from collections import deque
H, W = map(int,input().split())
grid = [list(input()) for _ in range(H)]


d = [[-1]*W for _ in range(H)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]


que = deque()
for x in range(W):
    for y in range(H):
        if grid[y][x] == '#':
            d[y][x] = 0
            que.append([x,y])

while len(que) != 0:
    p = que.popleft()
    for i in range(4):
        nx = p[0] + dx[i]
        ny = p[1] + dy[i]
        #print(nx,ny)
        if 0 <= nx <= W-1 and 0 <= ny <= H-1 and grid[ny][nx] == '.' and d[ny][nx] == -1:
            que.append([nx,ny])
            d[ny][nx] = d[p[1]][p[0]] + 1

# print(d)
# print(d[H-1][W-1])
res = 0
for x in range(W):
    for y in range(H):
        res = max(res,d[y][x])
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
#input = sys.stdin.readline
h, w = map(int,input().split())
grid = np.array([list(input()) for _ in range(h)])

large_grid = np.array([["." for _ in range(w+2)] for _ in range(h+2)])
goal_grid = [["#" for _ in range(w)] for _ in range(h)]
cnt = 0

for i in range(1000):
    if (grid == goal_grid).all():
        print(cnt)
        break
    for row in range(h):
        for col in range(w):
            if grid[row][col] == "#":
                large_grid[row][col+1] = "#"
                large_grid[row+2][col+1] = "#"
                large_grid[row+1][col+1] = "#"
                large_grid[row+1][col+2] = "#"
                large_grid[row+1][col] = "#"

    grid3 = large_grid[1:h+1, 1:w+1]
    #grid = grid3#参照元とかの問題でバグる
    grid = np.copy(grid3)
    cnt +=1

#     grid = grid2
#     print(grid2)
#     print(grid)








Fixed submission:
from collections import deque
H, W = map(int,input().split())
grid = [list(input()) for _ in range(H)]


d = [[-1]*W for _ in range(H)]
dx = [0,1,0,-1]
dy = [1,0,-1,0]


que = deque()
for x in range(W):
    for y in range(H):
        if grid[y][x] == '#':
            d[y][x] = 0
            que.append([x,y])

while len(que) != 0:
    p = que.popleft()
    for i in range(4):
        nx = p[0] + dx[i]
        ny = p[1] + dy[i]
        #print(nx,ny)
        if 0 <= nx <= W-1 and 0 <= ny <= H-1 and grid[ny][nx] == '.' and d[ny][nx] == -1:
            que.append([nx,ny])
            d[ny][nx] = d[p[1]][p[0]] + 1

# print(d)
# print(d[H-1][W-1])
res = 0
for x in range(W):
    for y in range(H):
        res = max(res,d[y][x])
print(res)