結果
| 問題 | No.34 砂漠の行商人 | 
| コンテスト | |
| ユーザー |  yaoshimax | 
| 提出日時 | 2015-02-15 20:38:26 | 
| 言語 | Python2 (2.7.18) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 662 bytes | 
| コンパイル時間 | 111 ms | 
| コンパイル使用メモリ | 7,040 KB | 
| 実行使用メモリ | 28,928 KB | 
| 最終ジャッジ日時 | 2024-06-23 20:22:59 | 
| 合計ジャッジ時間 | 7,439 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 5 TLE * 1 -- * 20 | 
ソースコード
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 len(que)!=0:
    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
            
            
            
        