Problem p03053 (python)

Fixed submission:
import collections
H,W=map(int,input().split())
went=[[False]*W for i in range(H)]
queue=collections.deque()
for hoge in range(H):
    for huga,t in enumerate(input()):
        if t=="#":
            went[hoge][huga]=True
            queue.append([hoge,huga,0])
while queue:
    curx,cury,ct=queue.popleft()
    for dx,dy in [[1,0],[-1,0],[0,1],[0,-1]]:
        newx,newy=curx+dx,cury+dy
        newct=ct+1
        if 0<=newx<H and 0<=newy<W and (not went[newx][newy]):
            went[newx][newy]=True
            queue.append([newx,newy,newct])
print(ct)

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
import collections
import copy
deque=collections.deque
fastinput=sys.stdin.readline
whites=deque()
firstwhite=deque()
H,W=map(int,input().split())
A=[list(fastinput().rstrip()) for j in range(H)]
rinsetsu=np.zeros((H*W,H*W),dtype="bool")
F=np.zeros((1,H*W),dtype="bool")

def UDLR(i,j):#各フラグごとに、白なら隣接追加　黒ならfirstwhite追加
    ID=W*i+j
    next2black=0
    rinsetsu[ID][ID]=1
    if i!=0:
        if A[i-1][j]==".":
            rinsetsu[ID][ID-W]=1
        else:F[0][ID]=1
    if i!=H-1:
        if A[i+1][j]==".":
            rinsetsu[ID][ID+W]=1
        else:F[0][ID]=1
    if j!=0:
        if A[i][j-1]==".":
            rinsetsu[ID][ID-1]=1
        else:F[0][ID]=1
    if j!=W-1:
        if A[i][j+1]==".":
            rinsetsu[ID][ID+1]=1
        else:F[0][ID]=1      

for k,i in enumerate(A):
    for l,j in enumerate(i):
        if j==".":
            whites.append(W*k+l)
            UDLR(k,l)
whitess=len(whites)
rinsetsuMatrix=np.matrix(rinsetsu)
ct=1
while 1:
    ct+=1
    F=np.dot(F,rinsetsuMatrix)
    sums=np.array(np.sum(F, axis=0))
    if sum([bool(i) for i in sums[0]])==whitess:
        print(ct)
        break

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
import collections
deque=collections.deque
fastinput=sys.stdin.readline
whites=deque()
firstwhite=deque()
H,W=map(int,input().split())
A=[list(fastinput().rstrip()) for j in range(W)]
rinsetsu=np.zeros((H*W,H*W),dtype="bool")
F=np.zeros((1,H*W),dtype="bool")

def UDLR(i,j):#各フラグごとに、白なら隣接追加　黒ならfirstwhite追加
    ID=W*i+j
    next2black=0
    rinsetsu[ID][ID]=1
    if i!=0:
        if A[i-1][j]==".":
            rinsetsu[ID][ID-W]=1
        else:F[0][ID]=1
    if i!=H-1:
        if A[i+1][j]==".":
            rinsetsu[ID][ID+W]=1
        else:F[0][ID]=1
    if j!=0:
        if A[i][j-1]==".":
            rinsetsu[ID][ID-1]=1
        else:F[0][ID]=1
    if j!=W-1:
        if A[i][j+1]==".":
            rinsetsu[ID][ID+1]=1
        else:F[0][ID]=1      

for k,i in enumerate(A):
    for l,j in enumerate(i):
        if j==".":
            whites.append(W*k+l)
            UDLR(k,l)
whitess=len(whites)
rinsetsuMatrix=np.matrix(rinsetsu)
ct=1
while 1:
    ct+=1
    F=np.dot(F,rinsetsuMatrix)
    sums=np.array(np.sum(F, axis=0))
    if sum([bool(i) for i in sums[0]])==whitess:
        print(ct)
        break

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
import collections
import copy
deque=collections.deque
fastinput=sys.stdin.readline
whites=deque()
firstwhite=deque()
H,W=map(int,input().split())
A=[list(fastinput().rstrip()) for j in range(W)]
rinsetsu=np.zeros((H*W,H*W))
F=np.zeros((1,H*W))

def UDLR(i,j):#各フラグごとに、白なら隣接追加　黒ならfirstwhite追加
    ID=W*i+j
    next2black=0
    rinsetsu[ID][ID]=1
    if i!=0:
        if A[i-1][j]==".":
            rinsetsu[ID][ID-W]=1
        else:F[0][ID]=1
    if i!=H-1:
        if A[i+1][j]==".":
            rinsetsu[ID][ID+W]=1
        else:F[0][ID]=1
    if j!=0:
        if A[i][j-1]==".":
            rinsetsu[ID][ID-1]=1
        else:F[0][ID]=1
    if j!=W-1:
        if A[i][j+1]==".":
            rinsetsu[ID][ID+1]=1
        else:F[0][ID]=1      

for k,i in enumerate(A):
    for l,j in enumerate(i):
        if j==".":
            whites.append(W*k+l)
            UDLR(k,l)
whitess=len(whites)
rinsetsuMatrix=np.matrix(rinsetsu)
ct=1
while 1:
    ct+=1
    F=np.dot(F,rinsetsuMatrix)
    sums=np.array(np.sum(F, axis=0))
    if sum([bool(i) for i in sums[0]])==whitess:
        print(ct)
        break

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
import collections
import copy
deque=collections.deque
fastinput=sys.stdin.readline
whites=deque()
firstwhite=deque()
H,W=map(int,input().split())
A=[list(fastinput().rstrip()) for j in range(W)]
rinsetsu=np.zeros((H*W,H*W))
F=np.zeros((1,H*W))

def printsix(l):
    for i in range(5):
        print(l[6*i:6*i+6])

def UDLR(i,j):#各フラグごとに、白なら隣接追加　黒ならfirstwhite追加
    ID=W*i+j
    next2black=0
    rinsetsu[ID][ID]=1
    if i!=0:
        if A[i-1][j]==".":
            rinsetsu[ID][ID-W]=1
        else:F[0][ID]=1
    if i!=H-1:
        if A[i+1][j]==".":
            rinsetsu[ID][ID+W]=1
        else:F[0][ID]=1
    if j!=0:
        if A[i][j-1]==".":
            rinsetsu[ID][ID-1]=1
        else:F[0][ID]=1
    if j!=W-1:
        if A[i][j+1]==".":
            rinsetsu[ID][ID+1]=1
        else:F[0][ID]=1      

for k,i in enumerate(A):
    for l,j in enumerate(i):
        if j==".":
            whites.append(W*k+l)
            UDLR(k,l)
whitess=len(whites)
rinsetsuMatrix=np.matrix(rinsetsu)
ct=1
for i in range(5):
    ct+=1
    F=np.dot(F,rinsetsuMatrix)
    sums=np.array(np.sum(F, axis=0))
    if sum([bool(i) for i in sums[0]])==whitess:
        print(ct)
        break