Problem p03053 (python)

Fixed submission:
from collections import deque
 
 
h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
d = deque()
memo = [[-1] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
a = tuple(input() for _ in hs)
b = [[i, j] for i in hs for j in ws if a[i][j] == '#']
for i, j in b:
    d.append((i, j))
    memo[i][j] = 0
while d:
    dh, dw = d.popleft()
    for i, j in move:
        dhn, dwn = dh + i, dw + j
        if (0 <= dhn < h) and (0 <= dwn < w) and (memo[dhn][dwn] < 0):
            d.append((dhn, dwn))
            memo[dhn][dwn] = memo[dh][dw] + 1
ans = max([max(e) for e in memo])
print(ans)

Buggy submission (verdict: Runtime Error):
h, w, n = map(int, input().split())
sr, sc = map(int, input().split())
s = list(input())
t = list(input())
sl_move, sr_move, su_move, sd_move = [], [], [], []
tl_move, tr_move, tu_move, td_move = [], [], [], []
for i in s:
    if i == 'L':
        sl_move += [-1]
        sr_move += [0]
        su_move += [0]
        sd_move += [0]
    elif i == 'R':
        sl_move += [0]
        sr_move += [1]
        su_move += [0]
        sd_move += [0]
    elif i == 'U':
        sl_move += [0]
        sr_move += [0]
        su_move += [-1]
        sd_move += [0]
    elif i == 'D':
        sl_move += [0]
        sr_move += [0]
        su_move += [0]
        sd_move += [1]
for i in t:
    if i == 'L':
        tl_move += [-1]
        tr_move += [0]
        tu_move += [0]
        td_move += [0]
    elif i == 'R':
        tl_move += [0]
        tr_move += [1]
        tu_move += [0]
        td_move += [0]
    elif i == 'U':
        tl_move += [0]
        tr_move += [0]
        tu_move += [-1]
        td_move += [0]
    elif i == 'D':
        tl_move += [0]
        tr_move += [0]
        tu_move += [0]
        td_move += [1]
ru, rd, cr, cl = sr, sr, sc, sc
for i in range(n):
    ru += su_move[i]
    if ru < 1:
        ans = 'NO'
        break
    ru += td_move[i]
    if ru > h:
        ru = h
    rd += sd_move[i]
    if rd > h:
        ans = 'NO'
        break
    rd += tu_move[i]
    if rd < 1:
        rd = 1
    cr += sr_move[i]
    if cr > w:
        ans = 'NO'
        break
    cr += tl_move[i]
    if cr < 1:
        cr = 1
    cl += sl_move[i]
    if cl < 1:
        ans = 'NO'
        break
    cl += tr_move[i]
    if cl > w:
        cl = w
    ans = 'YES'
print(ans)

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


h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
a = []
b = []
d = deque([])
memo = [[None] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
a = tuple(input() for _ in hs)
b = [[i, j] for i in hs for j in ws if a[i][j] == '#']
for i, j in b:
    d.append([i, j])
    memo[i][j] = 0


def d_list_update():
    dh, dw = d.popleft()
    for i, j in move:
        if not(memo[dh + i][dw + j]):
            if (0 <= dh + i < h) and (0 <= dw + j < w):
                memo[dh + i][dw + j] = memo[dh][dw] + 1
                d.append([dh + i, dw + j])
    return d


while d:
    d_list_update()
ans = max([max(e) for e in memo])
print(ans)

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


h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
a = []
d = deque([])
memo = [[None] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for i in hs:
    a.append(list(input()))
for i in hs:
    for j in ws:
        if a[i][j] == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax) and not(memo[dh + i][dw + j]):
            memo[dh + i][dw + j] = memo[dh][dw] + 1
            d.append([dh + i, dw + j])
    return d


hw = set(range(h*w))
for i in hw:
    d = d_list_update(d, h, w)
    if not d:
        break
ans = max([max(e) for e in memo])
print(ans)

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


h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
a = []
d = deque([])
memo = [[None] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
a = [list(input()) for i in hs]
for i in hs:
    for j in ws:
        if a[i][j] == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax) and not(memo[dh + i][dw + j]):
            memo[dh + i][dw + j] = memo[dh][dw] + 1
            d.append([dh + i, dw + j])
    return d


hw = set(range(h*w))
for i in hw:
    d = d_list_update(d, h, w)
    if not d:
        break
ans = max([max(e) for e in memo])
print(ans)

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


h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
a = []
d = deque([])
memo = [[None] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
a = [input() for i in hs]
for i in hs:
    for j in ws:
        if a[i][j] == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax) and not(memo[dh + i][dw + j]):
            memo[dh + i][dw + j] = memo[dh][dw] + 1
            d.append([dh + i, dw + j])
    return d


hw = set(range(h*w))
for i in hw:
    d = d_list_update(d, h, w)
    if not d:
        break
ans = max([max(e) for e in memo])
print(ans)

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


h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
a = []
d = deque([])
memo = [[None] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for i in hs:
    a.append(list(input()))
for i in hs:
    for j in ws:
        if a[i][j] == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax) and not(memo[dh + i][dw + j]):
            memo[dh + i][dw + j] = memo[dh][dw] + 1
            d.append([dh + i, dw + j])
    return d


hw = set(range(h*w))
for i in hw:
    d = d_list_update(d, h, w)
    if not d:
        break
ans = max([max(e) for e in memo])
print(ans)

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


h, w = map(int, input().split())
hs, ws = set(range(h)), set(range(w))
a = []
d = deque([])
memo = [[None] * w for j in hs]
move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
for i in hs:
    a.append(list(input()))
for i in hs:
    for j in ws:
        if a[i][j] == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax) and not(memo[dh + i][dw + j]):
            memo[dh + i][dw + j] = memo[dh][dw] + 1
            d.append([dh + i, dw + j])
    return d


hw = set(range(h*w))
for i in hw:
    d = d_list_update(d, h, w)
ans = max([max(e) for e in memo])
print(ans)

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


h, w = map(int, input().split())
a = []
d = deque([])
memo = [[-1] * w for j in range(h)]
for i in range(h):
    a.append(list(input()))
    for j, s in enumerate(a[i]):
        if s == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    counter[0] += 1
    move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax):
            if memo[dh + i][dw + j] == -1:
                memo[dh + i][dw + j] = memo[dh][dw] + 1
                d.append([dh + i, dw + j])
    return d


while(d):
    d = d_list_update(d, h, w)
ans = max([max(e) for e in memo])
print(ans)

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


h, w = map(int, input().split())
time1 = time.time()
a = []
d = deque([])
memo = [[-1] * w for j in range(h)]
for i in range(h):
    a.append(list(input()))
    for j, s in enumerate(a[i]):
        if s == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax):
            if memo[dh + i][dw + j] == -1:
                memo[dh + i][dw + j] = memo[dh][dw] + 1
                d.append([dh + i, dw + j])
    return d


while(d):
    d = d_list_update(d, h, w)
ans = max([max(e) for e in memo])
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
from collections import deque
import sys


sys.setrecursionlimit(10000)
h, w = map(int, input().split())
a = []
d = deque([])
memo = [[-1]*w for j in range(h)]
for i in range(h):
    a.append(list(input()))
    for j, s in enumerate(a[i]):
        if s == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax):
            if memo[dh + i][dw + j] == -1:
                memo[dh + i][dw + j] = memo[dh][dw] + 1
                d.append([dh + i, dw + j])
    return d


def abc(d, hmax, wmax):
    d = d_list_update(d, hmax, wmax)
    if d:
        abc(d, hmax, wmax)
    return 0


abc(d, h, w)
ans = np.amax(np.array(memo))
print(ans)

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


h, w = map(int, input().split())
a = []
d = deque([])
memo = [[-1]*w for j in range(h)]
for i in range(h):
    a.append(list(input()))
    for j, s in enumerate(a[i]):
        if s == '#':
            d.append([i, j])
            memo[i][j] = 0


def d_list_update(d, hmax, wmax):
    move = [[1, 0], [0, 1], [-1, 0], [0, -1]]
    dh, dw = d.popleft()
    for i, j in move:
        if (0 <= dh + i < hmax) and (0 <= dw + j < wmax):
            if memo[dh + i][dw + j] == -1:
                memo[dh + i][dw + j] = memo[dh][dw] + 1
                d.append([dh + i, dw + j])
    return d


def abc(d, hmax, wmax):
    d = d_list_update(d, hmax, wmax)
    if d:
        abc(d, hmax, wmax)
    return 0


abc(d, h, w)
ans = np.amax(np.array(memo))
print(ans)