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

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

INF = -1
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque()
for i in range(H):
    a = input()
    for j in range(W):
        if a[j] == "#":
            q.append([i, j, 0])
            dist_map[i][j] = 0

max_dist = 0

while len(q) > 0:
    current_h, current_w, dist = q.popleft()
    if max_dist < dist:
        max_dist = dist
    dist_map[current_h][current_w] = dist
    for dir in range(4):
        nh = current_h + n_i[dir]
        nw = current_w + n_j[dir]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if dist_map[nh][nw] != INF:
            continue
        q.append((nh, nw, dist+1))


print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

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

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

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque()
for i in range(H):
    a = input()
    for j in range(W):
        if a[j] == "#":
            q.append([i, j, 0])
            dist_map[i][j] = 0

max_dist = 0

while len(q) > 0:
    current_h, current_w, dist = q.popleft()
    if max_dist < dist:
        max_dist = dist
    dist_map[current_h][current_w] = dist
    for dir in range(4):
        nh = current_h + n_i[dir]
        nw = current_w + n_j[dir]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if dist_map[nh][nw] != INF:
            continue
        q.append((nh, nw, dist+1))


print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

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

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

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque([])
for i in range(H):
    a = input()
    for j in range(W):
        if a[j] == "#":
            q.append([i, j, 0])
            dist_map[i][j] = 0

max_dist = 0

while len(q) > 0:
    current = q.popleft()
    current_h = current[0]
    current_w = current[1]
    dist = current[2]

    if max_dist < dist:
        max_dist = dist
    dist_map[current_h][current_w] = dist
    for dir in range(4):
        nh = current_h + n_i[dir]
        nw = current_w + n_j[dir]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if dist_map[nh][nw] != INF:
            continue
        q.append((nh, nw, dist+1))


print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

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

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

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
a = [input() for i in range(H)]

dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque([])
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            q.append([i, j, 0])

max_dist = 0

while len(q) > 0:
    current = q.popleft()
    current_h = current[0]
    current_w = current[1]
    dist = current[2]
    if dist_map[current_h][current_w] != INF:
        continue
    if max_dist < dist:
        max_dist = dist
    dist_map[current_h][current_w] = dist
    for dir in range(4):
        nh = current_h + n_i[dir]
        nw = current_w + n_j[dir]
        if nh < 0 or H <= nh or nw < 0 or W <= nw:
            continue
        if a[nh][nw] == "#":
            continue
        q.append((nh, nw, dist+1))


print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

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

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

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
a = [input() for i in range(H)]

dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque([])
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            q.append([i, j, 0])

max_dist = 0
def update(c_h, c_w, d_map, dist, q):
    global max_dist
    if d_map[c_h][c_w] != INF:
        return
    if max_dist < dist:
        max_dist = dist
    d_map[c_h][c_w] = dist
    for dir in range(4):
        if c_h+n_i[dir] < 0 or H <= c_h+n_i[dir] or c_w+n_j[dir] < 0 or W <= c_w+n_j[dir]:
            continue
        if a[c_h+n_i[dir]][c_w+n_j[dir]] == "#":
            continue
        q.append((c_h+n_i[dir], c_w+n_j[dir], dist+1))

while len(q) > 0:
    current = q.popleft()
    current_h = current[0]
    current_w = current[1]
    dist = current[2]
    update(current_h, current_w, dist_map, dist, q)


print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

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

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

INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
a = [input() for i in range(H)]

dist_map = [[INF]*W for _ in range(H)]

# 黒マスの位置を記録
q = deque([])
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            q.append([i, j, 0])

def update(c_h, c_w, d_map, dist, q):
    if d_map[c_h][c_w] != INF:
        return
    d_map[c_h][c_w] = dist
    for dir in range(4):
        if c_h+n_i[dir] < 0 or H <= c_h+n_i[dir] or c_w+n_j[dir] < 0 or W <= c_w+n_j[dir]:
            continue
        if a[c_h+n_i[dir]][c_w+n_j[dir]] == "#":
            continue
        q.append((c_h+n_i[dir], c_w+n_j[dir], dist+1))

while len(q) > 0:
    current = q.popleft()
    current_h = current[0]
    current_w = current[1]
    dist = current[2]
    update(current_h, current_w, dist_map, dist, q)

max_dist = 0
for i in range(H):
    for j in range(W):
        if max_dist < dist_map[i][j] and dist_map[i][j] != INF:
            max_dist = dist_map[i][j]
print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
a = []
INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
for i in range(H):
    a.append(input())

dist_map = [[INF]*W for _ in range(H)]
# 黒マスの位置を記録
black_pos = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_pos.append([i, j])

def update(c_h, c_w, d_map, dist, q):
    if d_map[c_h][c_w] != INF:
        return
    d_map[c_h][c_w] = dist
    for dir in range(4):
        if c_h+n_i[dir] < 0 or H <= c_h+n_i[dir] or c_w+n_j[dir] < 0 or W <= c_w+n_j[dir]:
            continue
        if a[c_h+n_i[dir]][c_w+n_j[dir]] == "#":
            continue
        q.append((c_h+n_i[dir], c_w+n_j[dir], dist+1))

q = [(pos[0], pos[1], 0) for pos in black_pos]
while len(q) > 0:
    current = q.pop(0)
    current_h = current[0]
    current_w = current[1]
    dist = current[2]
    update(current_h, current_w, dist_map, dist, q)

max_dist = 0
for i in range(H):
    for j in range(W):
        if max_dist < dist_map[i][j] and dist_map[i][j] != INF:
            max_dist = dist_map[i][j]
print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
a = []
INF = 10**9
n_i = [-1, 0, 1, 0]
n_j = [0, -1, 0, 1]
for i in range(H):
    a.append(input())

dist_map = [[INF]*W for _ in range(H)]
# 黒マスの位置を記録
black_pos = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_pos.append([i, j])

def update(c_h, c_w, d_map, dist, q):
    if d_map[c_h][c_w] != INF:
        return
    d_map[c_h][c_w] = dist
    for dir in range(4):
        if c_h+n_i[dir] < 0 or H <= c_h+n_i[dir] or c_w+n_j[dir] < 0 or W <= c_w+n_j[dir]:
            continue
        if a[c_h+n_i[dir]][c_w+n_j[dir]] == "#":
            continue
        q.append((c_h+n_i[dir], c_w+n_j[dir], dist+1))

q = [(pos[0], pos[1], 0) for pos in black_pos]
while len(q) > 0:
    current = q.pop(0)
    current_h = current[0]
    current_w = current[1]
    dist = current[2]
    update(current_h, current_w, dist_map, dist, q)

max_dist = 0
for i in range(H):
    for j in range(W):
        if max_dist < dist_map[i][j] and dist_map[i][j] != INF:
            max_dist = dist_map[i][j]
print(max_dist)


Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
a = [input() for i in range(H)]

# 黒マスの位置を記録
stack = []
black_map = [[ a[i][j] == "#" for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            stack.append([i, j])

cnt = 0
while True:
    _stack = []
    for pos in stack:
        for i in [[-1,0], [1, 0], [0, -1], [0, 1]]:
            _x = pos[0] + i[0]
            _y = pos[1] + i[1]
            if 0 <= _x <= H-1 and 0 <= _y <= W-1 and not black_map[_x][_y]:
                _stack.append([_x, _y])
                black_map[_x][_y] = True
    if len(_stack) > 0:
        stack = _stack[::]
    else:
        break
    cnt += 1
print(cnt)

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
a = []
INF = 10 ** 9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
stack = []
black_map = [[ a[i][j] == "#" for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            stack.append([i, j])

cnt = 0
while True:
    _stack = []
    for pos in stack:
        for i in [[-1,0], [1, 0], [0, -1], [0, 1]]:
            _x = pos[0] + i[0]
            _y = pos[1] + i[1]
            if 0 <= _x <= H-1 and 0 <= _y <= W-1 and not black_map[_x][_y]:
                _stack.append([_x, _y])
                black_map[_x][_y] = True
    if len(_stack) > 0:
        stack = _stack[::]
    else:
        break
    cnt += 1
print(cnt)

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
a = []
INF = 10 ** 9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
black_stack = []
black_map = {}
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_stack.append([i, j])
            black_map[str(i) + ":" + str(j)] = True

cnt = 0
while len(black_map.keys()) != H*W:
    next_stack = []
    cnt += 1
    for pos in black_stack:
        for i in [[-1,0], [1, 0], [0, -1], [0, 1]]:
            if 0 <= pos[0] + i[0] <= H-1 and 0 <= pos[1] + i[1] <= W-1:
                    next_stack.append([pos[0] + i[0], pos[1] + i[1]])
                    if str(pos[0] + i[0]) + ":" + str(pos[1] + i[1]) not in black_map:
                        black_map[str(pos[0] + i[0]) + ":" + str(pos[1] + i[1])] = True
    black_stack = next_stack[::]
print(cnt)

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
a = []
INF = 10 ** 9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
black_stack = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_stack.append([i, j])
black_map = black_stack[::]
cnt = 0
while len(black_map) != H*W:
    next_stack = []
    cnt += 1
    for pos in black_stack:
        for i in [[-1,0], [1, 0], [0, -1], [0, 1]]:
            if 0 <= pos[0] + i[0] <= H-1 and 0 <= pos[1] + i[1] <= W-1:
                    next_stack.append([pos[0] + i[0], pos[1] + i[1]])
                    if [pos[0] + i[0], pos[1] + i[1]] not in black_map:
                        black_map.append([pos[0] + i[0], pos[1] + i[1]])
    black_stack = next_stack[::]
print(cnt)

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())

a_list = [list(input()) for i in range(H)]

isEnd = False
_a_list = a_list[::][::]
cnt = 0
while not isEnd:
    isEnd = True
    next_a_list = [["." for i in range(H)] for j in range(W)]
    for i in range(H):
        for j in range(W):
            a = _a_list[i][j]
            if a == ".":
                #  白色
                isEnd = False
            else:
                next_a_list[i][j] = "#"
                #  黒色
                if i > 0:
                    next_a_list[i-1][j] = "#"
                if i < H-1:
                    next_a_list[i+1][j] = "#"
                if j > 0:
                    next_a_list[i][j-1] = "#"
                if j < W-1:
                    next_a_list[i][j+1] = "#"
    cnt += 1
    _a_list = next_a_list[::]

print(cnt-1)

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []
INF = 10**9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
black_pos = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_pos.append([i, j])

# 白マスごとに最近傍の黒マスまでの距離を計算
dist_list = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            continue
        min_dist = INF
        for pos in black_pos:
            dist = abs(pos[0]-i) + abs(pos[1]-j)
            if dist < min_dist:
                min_dist = dist
        dist_list.append(min_dist)

print(max(dist_list))

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
a = []
INF = 10**9
for i in range(H):
    a.append(input())

# 黒マスの位置を記録
black_pos = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            black_pos.append([i, j])

# 白マスごとに最近傍の黒マスまでの距離を計算
dist_list = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            continue
        min_dist = INF
        for pos in black_pos:
            dist = abs(pos[0]-i) + abs(pos[1]-j)
            if dist < min_dist:
                min_dist = dist
        dist_list.append(min_dist)

print(max(dist_list))

Fixed submission:
from collections import deque
h,w = list(map(int,input().split()))
f = []
q = deque()
for i in range(h):
    a = list(input())
    for j in range(w):
        if a[j] == '#':
            q.append([0,i,j])
    f.append(a)
 
ans =0
dxy = [0,1,0,-1,0]
while(len(q)):
    c,y,x = q.popleft()
    for i in range(4):
        ny = y+dxy[i]
        nx = x+dxy[i+1]
        if nx >= w or ny >= h or nx <0 or ny <0:
            continue
        if f[ny][nx] == '.':
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
        elif f[ny][nx] != '#' and f[ny][nx] > c+1:
            f[ny][nx] = c+1
            q.append([c+1,ny,nx])
            ans = max(ans,c+1)
 
print(ans)