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


def main():

    h, w = map(int, input().split())
    a = ["#" * (w + 2)] + ["#" + input() + "#" for _ in range(h)] + ["#" * (w + 2)]

    d = [[-1] * (w + 2) for _ in range(h + 2)]

    def bfs():
        q = deque()
        for i in range(1, h + 1):
            for j in range(1, w + 1):
                if a[i][j] == "#":
                    q.append((j, i))
                    d[i][j] = 0

        dxy = (1, 0), (-1, 0), (0, 1), (0, -1)

        ans = 0
        while q:
            ux, uy = q.popleft()
            for dx, dy in dxy:
                vx = ux + dx
                vy = uy + dy
                if d[vy][vx] == -1 and a[vy][vx] == ".":
                    d[vy][vx] = d[uy][ux] + 1
                    ans = max(ans, d[vy][vx])
                    q.append((vx, vy))

        return ans

    ans = bfs()
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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


def main():

    h, w = map(int, input().split())
    a = ["#" * (w + 2)] + ["#" + input() + "#" for _ in range(h)] + ["#" * (w + 2)]

    d = [[-1] * (w + 2) for _ in range(h + 2)]

    def bfs():
        q = deque()
        for i in range(1, h + 1):
            for j in range(1, w + 1):
                if a[i][j] == "#":
                    q.append((j, i))
                    d[i][j] = 0

        dxy = (1, 0), (-1, 0), (0, 1), (0, -1)

        ans = 0
        while q:
            ux, uy = q.popleft()
            for dx, dy in dxy:
                vx = ux + dx
                vy = uy + dy
                if a[vy][vx] == "." and d[vy][vx] == -1:
                    d[vy][vx] = d[uy][ux] + 1
                    ans = max(ans, d[vy][vx])
                    q.append((vx, vy))

        return ans

    ans = bfs()
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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


def main():

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

    d = [[-1] * w for _ in range(h)]

    def bfs():
        q = deque()
        for i in range(h):
            for j in range(w):
                if a[i][j] == "#":
                    q.append((j, i))
                    d[i][j] = 0

        dxy = (1, 0), (-1, 0), (0, 1), (0, -1)

        ans = 0
        while q:
            ux, uy = q.popleft()
            for dx, dy in dxy:
                vx = ux + dx
                vy = uy + dy
                if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                    d[vy][vx] = d[uy][ux] + 1
                    ans = max(ans, d[vy][vx])
                    q.append((vx, vy))

        return ans

    ans = bfs()
    print(ans)


if __name__ == "__main__":
    main()


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs():
    q = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                q.append((j, i))
                d[i][j] = 0

    dxy = (1, 0), (-1, 0), (0, 1), (0, -1)

    ans = 0
    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                ans = max(ans, d[vy][vx])
                q.append((vx, vy))

    return ans


ans = bfs()
print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs():
    q = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                q.append((j, i))
                d[i][j] = 0

    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append((vx, vy))


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs():
    q = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                q.append((i, j))
                d[j][i] = 0

    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append((vx, vy))


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs():
    q = deque()
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                q.append((j, i))
                d[j][i] = 0

    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append((vx, vy))


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs():
    s = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                s.append([j, i])

    q = deque()
    for sx, sy in s:
        q.append([sx, sy])
        d[sy][sx] = 0
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append([vx, vy])


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs():
    s = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                s.append([i, j])

    q = deque()
    for sx, sy in s:
        q.append([sx, sy])
        d[sy][sx] = 0
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append([vx, vy])


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs():
    s = []
    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                s.append([i, j])

    q = deque()
    for sx, sy in s:
        q.append([sx, sy])
        d[sy][sx] = 0
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and \
                    a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append([vx, vy])


bfs()

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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

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

d = [[-1] * w for _ in range(h)]


def bfs(s):
    q = deque()
    for sx, sy in s:
        q.append([sx, sy])
        d[sy][sx] = 0
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy
            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 and\
                    a[vy][vx] == "." and d[vy][vx] == -1:
                d[vy][vx] = d[uy][ux] + 1
                q.append([vx, vy])


s = []
for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            s.append([i, j])

bfs(s)

ans = 0
for row in d:
    for e in row:
        ans = max(ans, e)

print(ans)


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

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


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

    q = deque()

    arrived = [[True] * (w + 2)] + \
              [[True] + [False] * w + [True] for _ in range(h)] + \
              [[True] * (w + 2)]

    for i in range(h):
        for j in range(w):
            if a[i][j] == "#":
                q.append([i+1, j+1])
                arrived[i+1][j+1] = True

    ans = 0
    while q:
        ans += 1
        pop_max = len(q)
        cnt = 0
        while cnt != pop_max:
            i, j = q.popleft()
            if not arrived[i-1][j]:
                arrived[i-1][j] = True
                q.append([i-1, j])

            if not arrived[i + 1][j]:
                arrived[i + 1][j] = True
                q.append([i + 1, j])

            if not arrived[i][j - 1]:
                arrived[i][j - 1] = True
                q.append([i, j - 1])

            if not arrived[i][j + 1]:
                arrived[i][j + 1] = True
                q.append([i, j + 1])

            cnt += 1

    ans -= 1
    print(ans)


def main():
    solve()


if __name__ == "__main__":
    main()


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy


def main():
    h, w = map(int, input().split())
    a = [["#"] * (w + 2)]\
        + [["#"] + list(input()) + ["#"] for _ in range(h)]\
        + [["#"] * (w + 2)]

    fin = [["#"] * (w + 2) for _ in range(h + 2)]

    cnt = 0
    while a != fin:
        cnt += 1
        tmp = deepcopy(a)
        for i in range(1, h + 1):
            for j in range(1, w + 1):
                if a[i][j] == "#":
                    tmp[i-1][j] = tmp[i+1][j] = tmp[i][j-1] = tmp[i][j+1] = "#"

        a = deepcopy(tmp)

    print(cnt)


if __name__ == "__main__":
    main()


Fixed submission:
from scipy.ndimage import distance_transform_cdt


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

    sq = [[1 if e == "." else 0 for e in row] for row in a]

    cnt = distance_transform_cdt(sq, metric="taxicab")

    print(cnt.max())


if __name__ == "__main__":
    main()