Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
H, W = map(int, input().split())
is_visited = [[False for w in range(W)] for h in range(H)]
q = Queue()
for h in range(H):
    Ah = list(input())
    for w in range(W):
        if Ah[w] == '#':
            q.put((h, w, 0))
            is_visited[h][w] = True
ans = 0
lrud = [
  [-1, 0],
  [1, 0],
  [0, -1],
  [0, 1]
]
while not q.empty():
    x, y, c = q.get()
    for dx, dy in lrud:
        nx = min(max(0, x+dx), H-1)
        ny = min(max(0, y+dy), W-1)
        if not is_visited[nx][ny]:
            q.put((nx, ny, c+1))
            is_visited[nx][ny] = True
    ans = c
print(ans)

Fixed submission:
INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
H, W = map(int, input().split())
A = [['.' for w in range(W)] for h in range(H)]
is_visited = [[False for w in range(W)] for h in range(H)]
q = Queue()
for h in range(H):
    A[h] = list(input())
    for w in range(W):
        if A[h][w] == '#':
            q.put((h, w, 0))
            is_visited[h][w] = True
ans = 0
lrud = [
  [-1, 0],
  [1, 0],
  [0, -1],
  [0, 1]
]
while not q.empty():
    x, y, c = q.get()
    for dx, dy in lrud:
        nx = min(max(0, x+dx), H-1)
        ny = min(max(0, y+dy), W-1)
        if not is_visited[nx][ny]:
            q.put((nx, ny, c+1))
            is_visited[nx][ny] = True
    ans = c
print(ans)

Fixed submission:
INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))

Buggy python submission (verdict: Time Limit Exceeded):
from queue import Queue
H, W = map(int, input().split())
A = [['.' for w in range(W)] for h in range(H)]
is_visited = [[False for w in range(W)] for h in range(H)]
q = Queue()
for h in range(H):
    A[h] = list(input())
    for w in range(W):
        if A[h][w] == '#':
            q.put((h, w, 0))
            is_visited[h][w] = True
ans = 0
lrud = [
  [-1, 0],
  [1, 0],
  [0, -1],
  [0, 1]
]
while not q.empty():
    x, y, c = q.get()
    for dx, dy in lrud:
        nx = min(max(0, x+dx), H-1)
        ny = min(max(0, y+dy), W-1)
        if not is_visited[nx][ny]:
            q.put((nx, ny, c+1))
            is_visited[nx][ny] = True
    ans = c
print(ans)

Fixed submission:
INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))

Buggy python submission (verdict: Time Limit Exceeded):
INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))


Fixed submission:
INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
ans = 2019
for i in range(2000):
    newA = deepcopy(A)
    count = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                if h > 0:
                    newA[h-1][w] = '#'
                if h < H-1:
                    newA[h+1][w] = '#'
                if w > 0:
                    newA[h][w-1] = '#'
                if w < W-1:
                    newA[h][w+1] = '#'
                count += 1
    A = deepcopy(newA)
    if count == H*W:
        ans = i
        break
print(ans)


Fixed submission:
INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))