Buggy python submission (verdict: Time Limit Exceeded):
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()


Fixed submission:
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()

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


def main():
    H, W = map(int, input().split())
    A = np.zeros([H, W])
    for h in range(H):
        A[h, :] = list(map(lambda x: 1 if x == "#" else 0, input()))

    costs = np.zeros([H, W])
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    s = np.where(A == 1)
    s = np.array(s)
    len_s = s.shape[1]
    q = []
    for i in range(len_s):
        q.append((s[0, i], s[1, i]))

    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if A[nx, ny] == 0:
                        costs[nx, ny] = moves
                        A[nx, ny] = 1
                        qn.append((nx, ny))

        q = qn
        if np.all(A == 1):
            break

    print(int(np.max(costs)))


main()


Fixed submission:
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()

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


def main():
    H, W = map(int, input().split())
    A = np.zeros([H, W])
    for h in range(H):
        A[h, :] = list(map(lambda x: 1 if x == "#" else 0, input()))

    costs = np.zeros([H, W])
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    s = np.where(A == 1)
    s = np.array(s)
    len_s = s.shape[1]
    q = []
    for i in range(len_s):
        q.append((s[0, i], s[1, i]))

    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if A[nx, ny] == 0:
                        costs[nx, ny] = moves
                        A[nx, ny] = 1
                        qn.append((nx, ny))

        q = qn

    print(int(np.max(costs)))


main()


Fixed submission:
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()

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

# 黒: #
# 白: .

H, W = input().split()

H = int(H)
W = int(W)

A = np.zeros([H,W])

for i in range(H):
    chars = np.array(list(input()))
    A[i,:] = np.where(chars=='.', 0, 1)

cnt = 0
w_num = np.sum(A == 0)

while w_num != 0:
    cnt += 1
    B = np.zeros([H+2,W+2])
    B[1:H+1,1:W+1] = A
#    for i in range(1,W+1):
#        for j in range(1,H+1):
#            B[i+1,j+1] = B[i+1,j+1] + B[i,j+1] + B[i+2,j+1] \
        #                            + B[i+1,j] + B[i+1,j+2]
#   for i in range(1,W+1)
#       for j in range(1,H+1)
#           B[i,j] = B[i,j] + B[i+1,j] + B[i-1,j]
#                           + B[i,j+1] + B[i,j-1]

    B[1:W+1,1:H+1] = B[1:W+1,1:H+1] + B[2:W+2,1:H+1] + B[0:W,1:H+1] \
                                    + B[1:W+1,2:H+2] + B[1:W+1,0:H]

    B = np.where(B == 0, 0, 1)
    A = B[1:H+1,1:W+1]
    w_num = np.sum(A== 0)
#    print(B)

print(cnt)

Fixed submission:
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()

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

# 黒: #
# 白: .

H, W = input().split()

H = int(H)
W = int(W)

A = np.zeros([H,W])

for i in range(H):
    chars = np.array(list(input()))
    A[i,:] = np.where(chars=='.', 0, 1)

cnt = 0
w_num = np.sum(A == 0)

while w_num != 0:
    cnt += 1
    B = np.zeros([H+2,W+2])
    B[1:H+1,1:W+1] = A

    C = np.zeros([H,W])
    for i in range(W):
        for j in range(H):
            C[i,j] = B[i+1,j+1] + B[i,j+1] + B[i+2,j+1] \
                            + B[i+1,j] + B[i+1,j+2]

    w_num = np.sum(C == 0)
    A = C
    print(A)

print(cnt)

Fixed submission:
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()

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

# 黒: #
# 白: .

H, W = input().split()

H = int(H)
W = int(W)

A = np.zeros([H,W])

for i in range(H):
    chars = np.array(list(input()))
    A[i,:] = np.where(chars=='.', 0, 1)

cnt = 0
w_num = np.sum(A == 0)

while w_num != 0:
    cnt += 1
    B = np.zeros([H,W])
    for i in range(W):
        for j in range(H):
            if A[i,j] == 1:
                B[i,j] = 1
                if i-1 >= 0:
                    B[i-1,j] = 1
                if i+1 < W:
                    B[i+1,j] = 1
                if j-1 >= 0:
                    B[i,j-1] = 1
                if j+1 < H:
                    B[i,j+1] = 1

    w_num = np.sum(B == 0)
    A = B

print(cnt)

Fixed submission:
def main():
    H, W = map(int, input().split())
    field = [list(input()) for _ in range(H)]
    dd = ((1, 0), (-1, 0), (0, 1), (0, -1))

    q = []
    for i in range(H):
        for j in range(W):
            if field[i][j] == "#":
                q.append((i, j))
                field[i][j] = 0
    moves = 0

    while q:
        qn = []
        moves += 1
        for x, y in q:
            for dx, dy in dd:
                nx, ny = int(x + dx), int(y + dy)
                if 0 <= nx < H and 0 <= ny < W:
                    if field[nx][ny] == ".":
                        field[nx][ny] = moves
                        qn.append((nx, ny))

        q = qn

    m = []
    for i in range(H):
        m.append(max(field[i]))
    print(max(m))


main()