Problem p03053 (python)

Fixed submission:
from collections import deque
import copy
H, W = map(int, input().split())
A = tuple(tuple(input()) for _ in range(H))
L=[[0]*W for _ in range(H)]
next_q=deque()

for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            L[i][j]=1
            next_q.append((i,j))

q=deque()

res = 0
while len(next_q) != 0:
    q=copy.copy(next_q)
    next_q.clear()
    while q:
        y, x = q.popleft()
        if y > 0 and L[y - 1][x] == 0:
            L[y - 1][x] = 1
            next_q.append((y - 1, x))
        if y < H - 1 and L[y + 1][x] == 0:
            L[y + 1][x] = 1
            next_q.append((y + 1, x))
        if x > 0 and L[y][x - 1] == 0:
            L[y][x - 1] = 1
            next_q.append((y, x - 1))
        if x < W - 1 and L[y][x + 1] == 0:
            L[y][x + 1] = 1
            next_q.append((y, x + 1))
    if len(next_q)==0: break
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):
from collections import deque
import copy
H, W = map(int, input().split())
A = tuple(tuple(input()) for _ in range(H))
L=[[0]*W for _ in range(W)]
next_q=deque()

for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            L[i][j]=1
            next_q.append((i,j))

q=deque()

res = 0
while len(next_q) != 0:
    q=copy.copy(next_q)
    next_q.clear()
    while q:
        y, x = q.popleft()
        if y > 0 and L[y - 1][x] == 0:
            L[y - 1][x] = 1
            next_q.append((y - 1, x))
        if y < H - 1 and L[y + 1][x] == 0:
            L[y + 1][x] = 1
            next_q.append((y + 1, x))
        if x > 0 and L[y][x - 1] == 0:
            L[y][x - 1] = 1
            next_q.append((y, x - 1))
        if x < W - 1 and L[y][x + 1] == 0:
            L[y][x + 1] = 1
            next_q.append((y, x + 1))
    if len(next_q)==0: break
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int, input().split())
A = tuple(tuple(input()) for _ in range(H))
next_q=deque([(i, j) for i in range(H) for j in range(W) if A[i][j] == '#'])
L = [[0] * W for _ in range(H)]
q=deque()

res = 0
while len(next_q) != 0:
    q=next_q.copy()
    next_q.clear()
    while q:
        y, x = q.popleft()
        if y > 0 and L[y - 1][x] == 0:
            L[y - 1][x] = 1
            next_q.append((y - 1, x))
        if y < H - 1 and L[y + 1][x] == 0:
            L[y + 1][x] = 1
            next_q.append((y + 1, x))
        if x > 0 and L[y][x - 1] == 0:
            L[y][x - 1] = 1
            next_q.append((y, x - 1))
        if x < W - 1 and L[y][x + 1] == 0:
            L[y][x + 1] = 1
            next_q.append((y, x + 1))
    if len(next_q)==0: break
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):


H, W = map(int, input().split())
A = tuple(tuple(input()) for _ in range(H))
next_q = [(i, j) for i in range(H) for j in range(W) if A[i][j] == '#']
L = [[0] * W for _ in range(H)]

res = 0
while len(next_q) != 0:
    q, next_q = next_q[:], []
    while len(q) != 0:
        y, x = q.pop(0)
        if y > 0 and L[y - 1][x] == 0:
            L[y - 1][x] = 1
            next_q.append((y - 1, x))
        if y < W - 1 and L[y + 1][x] == 0:
            L[y + 1][x] = 1
            next_q.append((y + 1, x))
        if x > 0 and L[y][x - 1] == 0:
            L[y][x - 1] = 1
            next_q.append((y, x - 1))
        if x < H - 1 and L[y][x + 1] == 0:
            L[y][x + 1] = 1
            next_q.append((y, x + 1))
    if len(next_q) == 0: break
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=tuple(tuple(input()) for _ in range(H))
next_q=[(i,j) for i in range(H) for j in range(W) if A[i][j]=='#']
L=[[0]*W for _ in range(H)]

res=0
while len(next_q)!=0:
    q,next_q=next_q[:],[]
    while len(q)!=0:
        x,y=q.pop(0)
        if x>0 and L[x-1][y]==0:
            L[x-1][y]=1
            next_q.append((x-1,y))
        if x<W-1 and L[x+1][y]==0:
            L[x+1][y]=1
            next_q.append((x+1,y))
        if y>0 and L[x][y-1]==0:
            L[x][y-1]=1
            next_q.append((x,y-1))
        if y<H-1 and L[x][y+1]==0:
            L[x][y+1]=1
            next_q.append((x,y+1))
    if len(next_q)==0:break
    res+=1
print(res)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=tuple(tuple(input()) for _ in range(H))
next_q=[]
L=[[0]*W for _ in range(H)]
for i,row in enumerate(A):
    for j,c in enumerate(row):
        if c=='#':
            next_q.append((i,j))
            L[i][j]=1
res=-1
while len(next_q)!=0:
    q,next_q=next_q[:],[]
    if len(q)==0:break
    while len(q)!=0:
        x,y=q.pop(0)
        if x>0 and L[x-1][y]==0:
            L[x-1][y]=1
            next_q.append((x-1,y))
        if x<W-1 and L[x+1][y]==0:
            L[x+1][y]=1
            next_q.append((x+1,y))
        if y>0 and L[x][y-1]==0:
            L[x][y-1]=1
            next_q.append((x,y-1))
        if y<H-1 and L[x][y+1]==0:
            L[x][y+1]=1
            next_q.append((x,y+1))
    res+=1
print(res)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[tuple(input()) for _ in range(H)]
next_q=[]
L=[[0]*W for _ in range(H)]
for i,row in enumerate(A):
    for j,c in enumerate(row):
        if c=='#':
            next_q.append((i,j))
            L[i][j]=1
res=-1
while len(next_q)!=0:
    q,next_q=next_q[:],[]
    if len(q)==0:break
    while len(q)!=0:
        x,y=q.pop(0)
        if x>0 and L[x-1][y]==0:
            L[x-1][y]=1
            next_q.append((x-1,y))
        if x<W-1 and L[x+1][y]==0:
            L[x+1][y]=1
            next_q.append((x+1,y))
        if y>0 and L[x][y-1]==0:
            L[x][y-1]=1
            next_q.append((x,y-1))
        if y<H-1 and L[x][y+1]==0:
            L[x][y+1]=1
            next_q.append((x,y+1))
    res+=1
print(res)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[tuple(input()) for _ in range(H)]
q=[]
L=[[0]*W for _ in range(H)]
for i,row in enumerate(A):
    for j,c in enumerate(row):
        if c=='#':
            q.append((i,j))
            L[i][j]=-1
while len(q)!=0:
    x,y=q.pop(0)
    v=L[x][y]+1 if L[x][y]!=-1 else 1
    if x>0 and L[x-1][y]==0:
        L[x-1][y]=v
        q.append((x-1,y))
    if x<W-1 and L[x+1][y]==0:
        L[x+1][y]=v
        q.append((x+1,y))
    if y>0 and L[x][y-1]==0:
        L[x][y-1]=v
        q.append((x,y-1))
    if y<H-1 and L[x][y+1]==0:
        L[x][y+1]=v
        q.append((x,y+1))
print(max([max(l) for l in L]))

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
A=[tuple(input()) for _ in range(H)]
q=[]
L=[[0]*W for _ in range(H)]
for i,row in enumerate(A):
    for j,c in enumerate(row):
        if c=='#':
            q.append((i,j))
            L[i][j]=-1
print(q)
while len(q)!=0:
    x,y=q.pop(0)
    v=L[x][y]+1 if L[x][y]!=-1 else 1
    if x>0 and L[x-1][y]==0:
        L[x-1][y]=v
        q.append((x-1,y))
    if x<W-1 and L[x+1][y]==0:
        L[x+1][y]=v
        q.append((x+1,y))
    if y>0 and L[x][y-1]==0:
        L[x][y-1]=v
        q.append((x,y-1))
    if y<H-1 and L[x][y+1]==0:
        L[x][y+1]=v
        q.append((x,y+1))
print(max([max(l) for l in L]))