結果

問題 No.34 砂漠の行商人
ユーザー yaoshimax
提出日時 2015-02-15 20:45:29
言語 Python2
(2.7.18)
結果
TLE  
実行時間 -
コード長 654 bytes
コンパイル時間 106 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 30,496 KB
最終ジャッジ日時 2024-06-23 20:23:08
合計ジャッジ時間 7,579 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 5 TLE * 1 -- * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,V,Sy,Sx,Gy,Gx = map(int,raw_input().split())
L=[]
for i in range(N):
    line = map(int,raw_input().split())
    L.append(line)

que=deque([(0,Sx-1,Sy-1,V)])

arrived=[[0 for i in range(N)]for j in range(N)]
dxs=[1,0,-1,0]
dys=[0,1,0,-1]
while que:
    dist,x,y,v = que.popleft()
    if arrived[x][y]>v:
        continue
    arrived[x][y]=v
    #print dist,y,x,v
    if (x,y)==(Gx-1,Gy-1):
        print dist
        exit()
    for dx,dy in zip(dxs,dys):
        nx,ny=x+dx,y+dy
        if nx>=0 and ny >= 0 and nx <N and ny <N and arrived[nx][ny]<v-L[nx][ny] :
            que.append((dist+1,nx,ny,v-L[nx][ny]))
print -1
0