結果
| 問題 | No.34 砂漠の行商人 |
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-02-15 20:49:43 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 203 ms / 5,000 ms |
| コード長 | 694 bytes |
| コンパイル時間 | 787 ms |
| コンパイル使用メモリ | 7,072 KB |
| 実行使用メモリ | 7,040 KB |
| 最終ジャッジ日時 | 2024-06-28 10:05:43 |
| 合計ジャッジ時間 | 3,350 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
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] :
arrived[nx][ny]=v-L[nx][ny]
que.append((dist+1,nx,ny,v-L[nx][ny]))
print -1
yaoshimax