Problem p03546 (python)

Fixed submission:
magialist=[]
datalist=[]
h,w=map(int,input().split())
for i in range(10):
    add=list(map(int,input().split()))
    magialist.append(add)

for j in range(h):
    add1=list(map(int,input().split()))
    datalist.extend(add1)
 
storelist=[[[[] for i in range(10)] for i in range(10)] for i in range(10)]
    #わーシャルフロイド法
for i in range(10):
    for j in range(10):
            a=min(magialist[i][j],magialist[i][0]+magialist[0][j])
            storelist[0][i][j]=a
k=1
while k<=9:
    for i in range(10):
        for j in range(10):
                a=min(storelist[k-1][i][j],storelist[k-1][i][k]+storelist[k-1][k][j])
                storelist[k][i][j]=a
    k+=1

uselist=[]
                                                                                        
for j in range(10):
    uselist.append(storelist[9][j][1])
ans=0
for nums in range(h*w):
        if datalist[nums]==-1:
            continue
        else:
            for j in range(10):
                if datalist[nums]==j:
                    ans+=uselist[j]
print(ans)

Buggy submission (verdict: Runtime Error):
magialist=[]
datalist=[]
h,w=map(int,input().split())
#for i in range(10):
    #add=list(map(int,input().split()))
    #magialist.append(add)
add=list(map(int,input().split()))
for i in range(10):
    magialist.append(add)



for j in range(h):
    add1=list(map(int,input().split()))
    datalist.extend(add1)
 
storelist=[[[[] for i in range(10)] for i in range(10)] for i in range(10)]
    #わーシャルフロイド法
for i in range(10):
    for j in range(10):
            a=min(magialist[i][j],magialist[i][0]+magialist[0][j])
            storelist[0][i][j]=a
k=1
while k<=9:
    for i in range(10):
        for j in range(10):
                a=min(storelist[k-1][i][j],storelist[k-1][i][k]+storelist[k-1][k][j])
                storelist[k][i][j]=a
    k+=1

uselist=[]
                                                                                        
for j in range(10):
    uselist.append(storelist[9][j][1])
ans=0
for nums in range(h*w):
    
    for i in range(10):
        if datalist[nums]==-1:
            continue
        
        elif datalist[nums]==i:
            ans+=uselist[i]
print(ans)

Buggy submission (verdict: Runtime Error):
magialist=[]
datalist=[]
h,w=map(int,input().split())
for i in range(10):
    add=list(map(int,input().split()))
    magialist.append(add)
for j in range(h):
    add1=list(map(int,input().split()))
    datalist.extend(add1)
storelist=[[[]*10]*10]*10
    #わーシャルフロイド法
def warsyaru(i,j,k):
    if k==0:
            return min(magialist[i][j],magialist[i][0]+magialist[0][j])
            storelist[i][j][0].append(min(magialist[i][j],magialist[i][0]+magialist[0][j]))
            
    elif k>=1:
        return min(storelist[i][j][k-1],storelist[i][k][k-1]+storelist[k][j][k-1])
        storelist[i][j][k].append(storelist[i][j][k-1],storelist[i][k][k-1]+storelist[k][j][k-1])
uselist=[]
for j in range(10):
    uselist.append(warsyaru(j,1,9))
ans=0
for nums in range(h*w):
    
    for i in range(10):
        if datalist[nums]==-1:
            continue
        
        elif datalist[nums]==i:
            ans+=uselist[i]
print(ans)

Buggy submission (verdict: Runtime Error):
magialist=[]
datalist=[]
h,w=map(int,input().split())
for i in range(10):
    add=list(map(int,input().split()))
    magialist.append(add)
for j in range(h):
    add1=list(map(int,input().split()))
    datalist.extend(add1)
storelist=[[[]*10]*10]*10
    #わーシャルフロイド法
def warsyaru(i,j,k):
    if k==0:
            return min(magialist[i][j],magialist[i][0]+magialist[0][j])
            storelist[i][j][0].append(min(magialist[i][j],magialist[i][0]+magialist[0][j]))
            
    elif k>=1:
        return min(storelist[i][j][k-1],storelist[i][k][k-1]+storelist[k][j][k-1])
        storelist[i][j][k].append(storelist[i][j][k-1],storelist[i][k][k-1]+storelist[k][j][k-1])
uselist=[]
for j in range(10):
    uselist.append(warsyaru(j,1,9))
ans=0
for nums in range(h*w):
    for i in range(10):
    if datalist[num]=i
    ans+=uselist[i]
print(ans)