Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    board = [input().strip() for i in range(H)]
    check = [[False] * W for i in range(H)]

    q = deque()
    for y in range(H):
        for x in range(W):
            if board[y][x] == "#":
                q.append((0, x, y))
                check[y][x] = True
    
    ans = 0
    while len(q) > 0:
        cost, x, y = q.popleft()
        ans = max(ans, cost)
        for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
            if 0 <= nx and nx < W and 0 <= ny and ny < H:
                if board[ny][nx] == "." and not check[ny][nx]:
                    q.append((cost+1, nx, ny))
                    check[ny][nx] = True
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    board = [input().strip() for i in range(H)]
    min_ = [[int(1e5)] * W for i in range(H)]

    q = deque()
    for y in range(H):
        for x in range(W):
            if board[y][x] == "#":
                q.append((0, x, y))
                min_[y][x] = 0
    
    ans = 0
    while len(q) > 0:
        cost, x, y = q.popleft()
        min_[y][x] = cost
        ans = max(ans, cost)
        for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
            if 0 <= nx and nx < W and 0 <= ny and ny < H:
                if board[ny][nx] == "." and cost + 1 < min_[ny][nx]:
                    q.append((cost+1, nx, ny))
                    min_[ny][nx] = cost+1
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    board = [input().strip() for i in range(H)]
    min_ = [[int(1e5)] * W for i in range(H)]

    q = deque()
    for y in range(H):
        for x in range(W):
            if board[y][x] == "#":
                q.append((0, x, y))
    
    ans = 0
    while len(q) > 0:
        cost, x, y = q.popleft()
        if cost < min_[y][x]:
            min_[y][x] = cost
            ans = max(ans, cost)
            for nx, ny in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
                if 0 <= nx and nx < W and 0 <= ny and ny < H:
                    if board[ny][nx] == ".":
                        q.append((cost+1, nx, ny))
    print(ans)

if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
# import heapq
from collections import deque
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    a = [input().strip() for i in range(H)]

    INF = int(1e8)
    min_cost = [[INF] * W for i in range(H)]

    # q = []
    q = deque()
    for y in range(H):
        for x in range(W):
            if a[y][x] == "#":
                # heapq.heappush(q, (0, x, y))
                q.append((0, x, y))
    
    ans = 0
    while len(q) > 0:
        # cost, x, y = heapq.heappop(q)
        cost, x, y = q.popleft()
        # 最小コストでテーブルを更新
        if cost < min_cost[y][x]:
            ans = max(ans, cost)
            min_cost[y][x] = cost
            for nx, ny in [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]:
                if 0 <= nx and nx < W and 0 <= ny and ny < H:
                    if cost + 1 < min_cost[ny][nx]:
                        # heapq.heappush(q, (cost+1, nx, ny))
                        q.append((cost+1, nx, ny))
    
    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import heapq
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())
    a = [input().strip() for i in range(H)]

    INF = int(1e8)
    min_cost = [[INF] * W for i in range(H)]

    q = []
    for y in range(H):
        for x in range(W):
            if a[y][x] == "#":
                heapq.heappush(q, (0, x, y))
    
    ans = 0
    while len(q) > 0:
        cost, x, y = heapq.heappop(q)
        # 最小コストでテーブルを更新
        if cost < min_cost[y][x]:
            ans = max(ans, cost)
            min_cost[y][x] = cost
            for nx, ny in [(x, y-1), (x+1, y), (x, y+1), (x-1, y)]:
                if 0 <= nx and nx < W and 0 <= ny and ny < H:
                    if cost + 1 < min_cost[ny][nx]:
                        heapq.heappush(q, (cost+1, nx, ny))
    
    print(ans)



if __name__ == "__main__":
    main()

Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import sys
input = sys.stdin.readline

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

    white = [[False] * w for i in range(h)]

    q = deque()
    for y in range(h):
        for x in range(w):
            if board[y][x] == ".":
                white[y][x] = True
            else:
                q.append((x, y, 0))

    step = 0
    len_ = len(q)
    while len_ > 0:
        x, y, step = q.popleft()
        len_ -= 1
        for n_x, n_y in [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]:
            if 0 <= n_x and n_x < w and 0 <= n_y and n_y < h:
                if white[n_y][n_x]:
                    q.append((n_x, n_y, step+1))
                    len_ += 1
                    white[n_y][n_x] = False

    print(step)

if __name__ == "__main__":
    main()


Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()

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

h, w = map(int, input().split())
board = [list(input().strip()) for i in range(h)]

white = [[False] * w for i in range(h)]

q = deque()
for y in range(h):
    for x in range(w):
        if board[y][x] == ".":
            white[y][x] = True
        else:
            q.append((x, y, 0))

step = 0
while len(q) > 0:
    x, y, step = q.popleft()
    for n_x, n_y in [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]:
        if 0 <= n_x and n_x < w and 0 <= n_y and n_y < h:
            if white[n_y][n_x]:
                q.append((n_x, n_y, step+1))
                white[n_y][n_x] = False

print(step)


Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()

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

h, w = map(int, input().split())
board = [list(input().strip()) for i in range(h)]

white = [[False] * w for i in range(h)]

q = deque()
for y in range(h):
    for x in range(w):
        if board[y][x] == ".":
            white[y][x] = True
        else:
            q.append((x, y, 0))

ans = 0
while len(q) > 0:
    x, y, step = q.popleft()
    ans = max(ans, step)
    for n_x, n_y in [(x-1, y), (x+1, y), (x, y-1), (x, y+1)]:
        if 0 <= n_x and n_x < w and 0 <= n_y and n_y < h:
            if white[n_y][n_x]:
                q.append((n_x, n_y, step+1))
                white[n_y][n_x] = False

print(ans)


Fixed submission:
import numpy as np
import sys
input = sys.stdin.readline

def main():
    H, W = map(int, input().split())

    INF = int(1e7)
    a = np.array([list(map(lambda x: 0 if x=="#" else INF, list(input().strip()))) for i in range(H)])

    for i in range(H-1):
        a[i+1] = np.minimum(a[i] + 1, a[i+1])
    for i in range(H-1, 0, -1):
        a[i-1] = np.minimum(a[i] + 1, a[i-1])
    
    for i in range(W-1):
        a[:, i+1] = np.minimum(a[:, i] + 1, a[:, i+1])
    for i in range(W-1, 0, -1):
        a[:, i-1] = np.minimum(a[:, i] + 1, a[:, i-1])

    print(np.max(a))

if __name__ == "__main__":
    main()