Buggy python submission (verdict: Runtime Error):
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 1000, dtype=np.int64)
cost[grid[:, :]] = 0

for j in range(2):
    for i in range(h - 1):
        cost[i] = np.minimum(cost[i], cost[i + 1] + 1)
    for i in range(1, h)[::-1]:
        cost[i] = np.minimum(cost[i], cost[i - 1] + 1)
    for i in range(w - 1):
        cost[i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)
    for n in range(1, w)[::-1]:
        cost[i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

print(np.max(cost))

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

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

h, w = map(int, input().split())

todo = deque([])
draw = ((1, 0), (-1, 0), (0, 1), (0, -1))
done = [[0] * (w + 2)]
for i in range(h):
    done.append([0] + [1000 for _ in range(w)] + [0])
done.append([0] * (w + 2))

grid = [list("#" * (w + 2))]
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append((i + 1, j + 1))
            done[i + 1][j + 1] = 0
    grid.append(list("#" + s + "#"))
grid.append(list("#" * (w + 2)))

while todo:
    n, m = todo.popleft()
    d = done[n][m]
    for dn, dm in draw:
        if done[n + dn][m + dm] != 1000:
            pass
        elif done[n + dn][m + dm] > d + 1:
            todo.append((n + dn, m + dm))
            done[n + dn][m + dm] = d + 1

print(max(max(i) for i in done))

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

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

h, w = map(int, input().split())
grid = [input() for _ in range(h)]

move = (-w, -1, 1, w)
todo = deque([])
done = [1000 for _ in range(w * h)]
for i, j in enumerate(grid):
    for k, l in enumerate(j):
        if l == "#":
            todo.append(k + i * w)
            done[k + i * w] = 0

while todo:
    n = todo.popleft()
    d = done[n]
    for dn in move:
        if n % w == 0 and dn == -1:
            pass
        elif n % w == w - 1 and dn == 1:
            pass
        elif n < w and dn == -w:
            pass
        elif n >= w * h - w and dn == w:
            pass
        elif done[n + dn] <= d + 1:
            pass
        else:
            todo.append(n + dn)
            done[n + dn] = d + 1

print(max(done))

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

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

h, w = map(int, input().split())

move = (-w, -1, 1, w)
todo = deque([])
done = [1000 for _ in range(w * h)]
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append(j + i * w)
            done[j + i * w] = 0

while todo:
    n = todo.popleft()
    d = done[n]
    for dn in move:
        if n % w == 0 and dn == -1:
            pass
        elif n % w == w - 1 and dn == 1:
            pass
        elif n < w and dn == -w:
            pass
        elif n >= w * h - w and dn == w:
            pass
        elif done[n + dn] <= d + 1:
            pass
        else:
            todo.append(n + dn)
            done[n + dn] = d + 1

print(max(done))

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

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

h, w = map(int, input().split())

move = (-w, -1, 1, w)
todo = deque([])
done = [False for _ in range(w * h)]
grid = ""
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append(j + i * w)
            done[j + i * w] = True
    grid += s
grid = list(grid)

cnt = -1
while todo:
    for i in range(len(todo)):
        n = todo.popleft()
        for dn in move:
            if n % w == 0 and dn == -1:
                pass
            elif n % w == w - 1 and dn == 1:
                pass
            elif n < w and dn == -w:
                pass
            elif n >= w * h - w and dn == w:
                pass
            elif done[n + dn]:
                pass
            elif grid[n + dn] == "#":
                pass
            elif grid[n + dn] == ".":
                todo.append(n + dn)
                done[n + dn] = True
                grid[n + dn] = "#"
    cnt += 1

print(cnt)

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

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

h, w = map(int, input().split())

move = (-w, -1, 1, w)
todo = deque([])
done = [False for _ in range(w * h)]
grid = ""
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append(j + i * w)
            done[j + i * w] = True
    grid += s
grid = list(grid)

cnt = -1
while todo:
    for i in range(len(todo)):
        n = todo.popleft()
        for dn in move:
            if n % w == 0 and dn == -1:
                pass
            elif n % w == w - 1 and dn == 1:
                pass
            elif n < w and dn == -w:
                pass
            elif n >= w * h - w and dn == w:
                pass
            elif done[n + dn]:
                pass
            elif grid[n + dn] == "#":
                pass
            elif grid[n + dn] == ".":
                todo.append(n + dn)
                done[n + dn] = True
                grid[n + dn] = "#"
    cnt += 1

print(cnt)

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

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

h, w = map(int, input().split())

todo = deque([])
draw = ((1, 0), (-1, 0), (0, 1), (0, -1))
done = [[1] * (w + 2)]
for i in range(h):
    done.append([1] + [0 for _ in range(w)] + [1])
done.append([1] * (w + 2))

grid = [list("#" * (w + 2))]
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append((i + 1, j + 1))
            done[i + 1][j + 1] = 1
    grid.append(list("#" + s + "#"))
grid.append(list("#" * (w + 2)))

cnt = 0
while todo:
    tmp = deque([])
    while todo:
        n, m = todo.popleft()
        for dn, dm in draw:
            if done[n + dn][m + dm] != 0:
                pass
            elif grid[n + dn][m + dm] == "#":
                pass
            elif grid[n + dn][m + dm] == ".":
                tmp.append((n + dn, m + dm))
                done[n + dn][m + dm] = 1
                grid[n + dn][m + dm] = "#"
    todo = tmp
    cnt += 1

print(cnt - 1)

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

Buggy python submission (verdict: Runtime Error):
from collections import deque

h, w = map(int, input().split())

draw = ((1, 0), (-1, 0), (0, 1), (0, -1))
todo = deque([])
done = [[False for _ in range(w)] for _ in range(h)]
grid = []
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append((i, j))
            done[i][j] = True
    grid.append(list(s))

cnt = -1
while todo:
    for i in range(len(todo)):
        n, m = todo.popleft()
        for dn, dm in draw:
            if not 0 <= n + dn < w or not 0 <= m + dm < h:
                pass
            elif done[n + dn][m + dm]:
                pass
            elif grid[n + dn][m + dm] == "#":
                pass
            elif grid[n + dn][m + dm] == ".":
                todo.append((n + dn, m + dm))
                done[n + dn][m + dm] = True
                grid[n + dn][m + dm] = "#"
    cnt += 1

print(cnt)

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

Buggy python submission (verdict: Runtime Error):
from collections import deque

h, w = map(int, input().split())

draw = ((1, 0), (-1, 0), (0, 1), (0, -1))
todo = deque([])
done = [[False for _ in range(w)] for _ in range(h)]
grid = []
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append((i, j))
            done[i][j] = True
    grid.append(list(s))

cnt = 0
while todo:
    tmp = deque([])
    while todo:
        n, m = todo.popleft()
        for dn, dm in draw:
            if not 0 <= n + dn < w or not 0 <= m + dm < h:
                pass
            elif done[n + dn][m + dm]:
                pass
            elif grid[n + dn][m + dm] == "#":
                pass
            elif grid[n + dn][m + dm] == ".":
                tmp.append((n + dn, m + dm))
                done[n + dn][m + dm] = True
                grid[n + dn][m + dm] = "#"
    todo = tmp
    cnt += 1

print(cnt - 1)

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

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

h, w = map(int, input().split())

todo = deque([])
draw = ((1, 0), (-1, 0), (0, 1), (0, -1))
done = [[1] * (w + 2)]
for i in range(h):
    done.append([1] + [0 for _ in range(w)] + [1])
done.append([1] * (w + 2))

grid = [list("#" * (w + 2))]
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append((i + 1, j + 1))
            done[i + 1][j + 1] = 1
    grid.append(list("#" + s + "#"))
grid.append(list("#" * (w + 2)))

cnt = 0
while todo:
    tmp = deque([])
    while todo:
        n, m = todo.popleft()
        for dn, dm in draw:
            if done[n + dn][m + dm] != 0:
                pass
            elif grid[n + dn][m + dm] == "#":
                pass
            elif grid[n + dn][m + dm] == ".":
                tmp.append((n + dn, m + dm))
                done[n + dn][m + dm] = 1
                grid[n + dn][m + dm] = "#"
    todo = tmp
    cnt += 1

print(cnt - 1)

Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))

Buggy python submission (verdict: Time Limit Exceeded):
h, w = map(int, input().split())

todo = []
draw = ((1, 0), (-1, 0), (0, 1), (0, -1))
done = [[1] * (w + 2)]
for i in range(h):
    done.append([1] + [0 for _ in range(w)] + [1])
done.append([1] * (w + 2))

grid = [list("#" * (w + 2))]
for i in range(h):
    s = input()
    for j, k in enumerate(s):
        if k == "#":
            todo.append((i + 1, j + 1))
            done[i + 1][j + 1] = 1
    grid.append(list("#" + s + "#"))
grid.append(list("#" * (w + 2)))

cnt = 0
while todo:
    tmp = []
    while todo:
        n, m = todo.pop(0)
        for dn, dm in draw:
            if done[n + dn][m + dm] != 0:
                pass
            elif grid[n + dn][m + dm] == "#":
                pass
            elif grid[n + dn][m + dm] == ".":
                tmp.append((n + dn, m + dm))
                done[n + dn][m + dm] = 1
                grid[n + dn][m + dm] = "#"
    todo = tmp
    cnt += 1

print(cnt - 1)


Fixed submission:
import numpy as np

h, w = map(int, input().split())
grid = (np.array([list(input())
                  for _ in range(h)]) == "#")
cost = np.full((h, w), 10 ** 9, dtype=np.int64)
cost[grid[:, :]] = 0

for i in range(1, h):
    cost[i] = np.minimum(cost[i], cost[i - 1] + 1)

for i in range(h - 1)[::-1]:
    cost[i] = np.minimum(cost[i], cost[i + 1] + 1)

for i in range(1, w):
    cost[:, i] = np.minimum(cost[:, i], cost[:, i - 1] + 1)

for i in range(w - 1)[::-1]:
    cost[:, i] = np.minimum(cost[:, i], cost[:, i + 1] + 1)

print(np.max(cost))