Buggy python submission (verdict: Time Limit Exceeded):
# AGC033A - Darker and Darker (PyPy 400ms)
def bfs() -> None:
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    cur, q = 0, []
    # append default blacks to a queue
    q = [(x, y) for x in range(H) for y in range(W) if B[x][y] == 0]
    while q:  # append new blacks until all whites become black
        next_q = []
        for x, y in q:
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                    B[nx][ny] = cur + 1
                    next_q.append((nx, ny))
        q = next_q
        cur += 1
    return cur - 1


def main():
    global H, W, B
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    # default blacks: 0, whites: -1
    B = [[0 if i == "#" else -1 for i in a] for a in A]
    ans = bfs()
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# AGC033A - Darker and Darker
def bfs() -> None:
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    cur, q = 0, []
    for x, b in enumerate(B):
        for y, i in enumerate(b):
            if i != cur:
                continue
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                    B[nx][ny] = cur + 1
                    q.append((nx, ny))
    while q:
        cur += 1
        next_q = []
        for x, y in q:
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                    B[nx][ny] = cur + 1
                    next_q.append((nx, ny))
        q = next_q
    return cur


def main():
    global H, W, B
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    B = [[0 if i == "#" else -1 for i in a] for a in A]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    ans = bfs()
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# AGC033A - Darker and Darker
def main():
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    B = [[0 if i == "#" else -1 for i in a] for a in A]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    cur, flg = 0, 1
    while flg:
        flg = 0
        for x, b in enumerate(B):
            for y, i in enumerate(b):
                if i != cur:
                    continue
                for dx, dy in dxy:
                    nx, ny = x + dx, y + dy
                    if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                        B[nx][ny] = cur + 1
                        flg = 1
        cur += 1
    ans = cur - 1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# AGC033A - Darker and Darker
def main():
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    B = [[0 if i == "#" else -1 for i in a] for a in A]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    cur, flg = 0, 1
    while flg:
        flg = 0
        for x, b in enumerate(B):
            for y, i in enumerate(b):
                if i != cur:
                    continue
                for dx, dy in dxy:
                    nx, ny = x + dx, y + dy
                    if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                        B[nx][ny] = cur + 1
                        flg = 1
        cur += 1
    ans = cur - 1
    print(ans)


if __name__ == "__main__":
    main()

Fixed submission:
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# AGC033A - Darker and Darker
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.distance_transform_bf.html
from scipy.ndimage import distance_transform_bf as dist


def main():
    """
    distance_transform_bf:
        orig     taxicab / chessboard / euclidean
        1 1 1     2 1 2      1 1 1      1.4 1 1.4
        1 0 1 ->  1 0 1      1 0 1       1  0  1
        1 1 1     2 1 2      1 1 1      1.4 1 1.4
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = tuple(tuple(input()) for _ in range(h))
    B = tuple(tuple(1 if i == "." else 0 for i in a) for a in A)
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Fixed submission:
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "#" else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(max(D))


if __name__ == "__main__":
    main()

Fixed submission:
# AGC033A - Darker and Darker
from scipy.ndimage import distance_transform_cdt as dist


def main():
    """
    distance_transform_cdt(matric="taxicab"):
        0 0 0    1 1 1
        0 1 0 -> 1 0 1
        0 0 0    1 1 1
    """
    h, w = tuple(map(int, input().rstrip().split()))
    A = list(list(input()) for _ in range(h))
    B = [[1 if i == "." else 0 for i in a] for a in A]
    D = dist(B, metric="taxicab")
    print(D.max())


if __name__ == "__main__":
    main()