Problem p03053 (python)

Fixed submission:
from collections import deque

H, W = map(int, input().split())
a = [[0] * W for _ in range(H)]
q = deque([])
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            a[i][j] = 1
            q.appendleft((i, j, 0))

while True:
    try:
        i, j, val = q.pop()
        if i > 0 and a[i - 1][j] == 0:
            q.appendleft((i - 1, j, val + 1))
            a[i - 1][j] = 1
        if i < H - 1 and a[i + 1][j] == 0:
            q.appendleft((i + 1, j, val + 1))
            a[i + 1][j] = 1
        if j > 0 and a[i][j - 1] == 0:
            q.appendleft((i, j - 1, val + 1))
            a[i][j - 1] = 1
        if j < W - 1 and a[i][j + 1] == 0:
            q.appendleft((i, j + 1, val + 1))
            a[i][j + 1] = 1
    except:
        print(val)
        break

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


def func(x):
    if x == '.':
        return 2000
    else:
        return 0


H, W = map(int, input().split())
b = []
for _ in range(W):
    b.append(list(map(func, input())))
a = np.array(b)

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

print(np.max(a))

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


def func(x):
    if x == '.':
        return 2000
    else:
        return 0


H, W = map(int, input().split())
b = []
for _ in range(W):
    b.append(list(map(func, input())))
a = np.array(b)

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

print(max(a))

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


def func(x):
    if x == '.':
        return 2000
    else:
        return 0


H, W = map(int, input().split())
b = []
for _ in range(W):
    b.append(list(map(func, input())))
a = np.array(b)

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

print(np.max(a))

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


def func(x):
    if x == '.':
        return 2000
    else:
        return 0


H, W = map(int, input().split())
b = []
for _ in range(W):
    b.append(list(map(func, input())))
a = np.array(b)

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

print(np.max(a))

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

H, W = map(int, input().split())
b = []
for _ in range(W):
    b.append(list(map(int, input().replace('.', '0').replace('#', '1'))))
a = np.array(b)
num = 0

while (a == 0).any():
    ne = a.copy()
    ne[1:, :] += a[:-1, :]
    ne[:-1, :] += a[1:, :]
    ne[:, 1:] += a[:, :-1]
    ne[:, :-1] += a[:, 1:]
    num += 1
    a = ne

print(num)