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

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

q = deque()
done = set()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            q.append((i, j, 0))
            done.add((i, j))

while q:
    # print(q)
    i, j, k = q.popleft()
    if i > 0 and (i - 1, j) not in done:
        q.append((i - 1, j, k + 1))
        done.add((i - 1, j))
    if i < h - 1 and (i + 1, j) not in done:
        q.append((i + 1, j, k + 1))
        done.add((i + 1, j))
    if j > 0 and (i, j - 1) not in done:
        q.append((i, j - 1, k + 1))
        done.add((i, j - 1))
    if j < w - 1 and (i, j + 1) not in done:
        q.append((i, j + 1, k + 1))
        done.add((i, j + 1))

print(k)


Fixed submission:
import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

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

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)

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

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

q = deque()
done = set()
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            q.append((i, j, 0))
            done.add((i, j))

while q:
    i, j, k = q.popleft()
    done.add((i, j))
    if i > 0 and (i - 1, j) not in done:
        q.append((i - 1, j, k + 1))
    if i < h - 1 and (i + 1, j) not in done:
        q.append((i + 1, j, k + 1))
    if j > 0 and (i, j - 1) not in done:
        q.append((i, j - 1, k + 1))
    if j < w - 1 and (i, j + 1) not in done:
        q.append((i, j + 1, k + 1))

print(k)


Fixed submission:
import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

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

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import copy

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

a = [[(ai[j] == "#") for j in range(w)] for ai in a]

ans = 0
for _ in range(h + w):
    if np.all(a):
        break
    a_tmp = copy.deepcopy(a)

    for i in range(h):
        for j in range(w):
            if (not a[i][j]) and (
                (i != 0 and a_tmp[i - 1][j])
                or (i != h - 1 and a_tmp[i + 1][j])
                or (j != 0 and a_tmp[i][j - 1])
                or (j != w - 1 and a_tmp[i][j + 1])
            ):
                a[i][j] = True

    ans += 1

print(ans)


Fixed submission:
import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

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

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

a = np.array([[(ai[j] == "#") for j in range(w)] for ai in a])

a_arr = np.zeros((h + 2, w + 2), dtype="bool")
a_arr[1:-1, 1:-1] = a

for _ in range(h + w):
    if np.all(a_arr[1:-1, 1:-1]):
        print(_)
        break
    a_arr[1:-1, 1:-1] = (
        a_arr[1:-1, 1:-1]
        + a_arr[:-2, 1:-1]
        + a_arr[2:, 1:-1]
        + a_arr[1:-1, :-2]
        + a_arr[1:-1, 2:]
    )



Fixed submission:
import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

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

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

a = np.array([[(ai[j] == "#") for j in range(w)] for ai in a])


ans = 0
for _ in range(h + w):
    if np.all(a):
        break
    a_new = a.copy()

    for i in range(h):
        for j in range(w):
            if (not a_new[i, j]) and (
                (i != 0 and a[i - 1, j])
                or (i != h - 1 and a[i + 1, j])
                or (j != 0 and a[i, j - 1])
                or (j != w - 1 and a[i, j + 1])
            ):
                a_new[i, j] = True
    a = a_new
    ans += 1

print(ans)


Fixed submission:
import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

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

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

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

a = np.array([[(ai[j] == "#") for j in range(w)] for ai in a])


ans = 0
for _ in range(3000):
    if np.all(a):
        break
    a_new = a.copy()
    a_new[1:] = a_new[1:] + a[:-1]
    a_new[:-1] = a_new[:-1] + a[1:]
    a_new[:, 1:] = a_new[:, 1:] + a[:, :-1]
    a_new[:, :-1] = a_new[:, :-1] + a[:, 1:]
    a = a_new
    ans += 1
print(ans)


Fixed submission:
import numpy as np
from scipy.ndimage.morphology import distance_transform_cdt

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

a = np.array([[(ai[j] != "#") for j in range(w)] for ai in a])
d = distance_transform_cdt(a, metric="taxicab").max()
print(d)