Problem p03053 (python)

Fixed submission:
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

from collections import deque

q=deque([])
B=[[None]*H for _ in range (W)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

from collections import deque

q=deque([])
B=[[None]*H for _ in range (W)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
print(max([max(B[i]) for i in range(H)]))

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

import queue
q=queue.Queue()
B=[[None]*H for _ in range (W)]
cnt=0
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.put((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while q.empty()==False:
  XY=[]
  while q.empty()==False:
     XY.append(q.get())
  for xy in XY:
    for i in range(4):
      if 0<=xy[0]+dx[i]<=H-1 and 0<=xy[1]+dy[i]<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.put((xy[0]+dx[i],xy[1]+dy[i]))
print(max([max(B[i]) for i in range(H)]))

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

import queue
q=queue.Queue()
B=[[None]*H for _ in range (W)]
cnt=0
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.put((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while q.empty()==False:
  XY=[]
  while q.empty()==False:
     XY.append(q.get())
  for xy in XY:
    for i in range(4):
      if 0<=xy[0]+dx[i]<=H-1 and 0<=xy[1]+dy[i]<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.put((xy[0]+dx[i],xy[1]+dy[i]))
print(max([max(B[i]) for i in range(H)]))

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

import queue
q=queue.Queue()
B=[[0]*H for _ in range (W)]
cnt=0
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.put((i,j))
            B[i][j]=1
while sum([sum(B[k]) for k in range(H)])<H*W:
    new_q=[]
    while q.empty()==False:
        new_q.append(q.get())
    for t in new_q:
        if t[0]!=0:
            q.put((t[0]-1, t[1]))
            B[t[0]-1][t[1]]=1
        if t[0]!=H-1:
            q.put((t[0]+1, t[1]))
            B[t[0]+1][t[1]]=1
        if t[1]!=0:
            q.put((t[0], t[1]-1))
            B[t[0]][t[1]-1]=1
        if t[1]!=W-1:
            q.put((t[0], t[1]+1))
            B[t[0]][t[1]+1]=1
    cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
A=[input() for _ in range(H)]

B=[[0]*W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            B[i][j]=1
import copy
cnt=0
C=copy.copy(B)
while sum([sum(C[k]) for k in range(W)])<H*W:
    B=copy.deepcopy(C)
    cnt+=1
    for i in range(H):
        for j in range(W):
            if B[i][j]==1:
                if i>0:
                    C[i-1][j]=1
                if i<H-1:
                    C[i+1][j]=1
                if j>0:
                    C[i][j-1]=1
                if j<H-1:
                    C[i][j+1]=1
print(cnt)