結果

問題 No.34 砂漠の行商人
ユーザー TawaraTawara
提出日時 2015-12-30 00:20:37
言語 Python2
(2.7.18)
結果
AC  
実行時間 156 ms / 5,000 ms
コード長 490 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 6,736 KB
実行使用メモリ 7,180 KB
最終ジャッジ日時 2023-09-10 19:19:32
合計ジャッジ時間 2,550 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
6,544 KB
testcase_01 AC 14 ms
6,684 KB
testcase_02 AC 16 ms
6,480 KB
testcase_03 AC 13 ms
6,684 KB
testcase_04 AC 33 ms
6,724 KB
testcase_05 AC 39 ms
6,592 KB
testcase_06 AC 28 ms
6,648 KB
testcase_07 AC 71 ms
6,644 KB
testcase_08 AC 82 ms
6,772 KB
testcase_09 AC 62 ms
6,788 KB
testcase_10 AC 33 ms
7,000 KB
testcase_11 AC 50 ms
7,036 KB
testcase_12 AC 21 ms
6,712 KB
testcase_13 AC 155 ms
7,104 KB
testcase_14 AC 156 ms
7,180 KB
testcase_15 AC 16 ms
6,660 KB
testcase_16 AC 30 ms
6,640 KB
testcase_17 AC 17 ms
6,764 KB
testcase_18 AC 17 ms
6,492 KB
testcase_19 AC 72 ms
6,988 KB
testcase_20 AC 108 ms
6,952 KB
testcase_21 AC 19 ms
6,840 KB
testcase_22 AC 21 ms
6,756 KB
testcase_23 AC 17 ms
6,772 KB
testcase_24 AC 120 ms
7,100 KB
testcase_25 AC 30 ms
6,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from Queue import deque
I=lambda:map(int,raw_input().split())
N,V,Sx,Sy,Gx,Gy=I();Sx-=1;Sy-=1;Gx-=1;Gy-=1
L=[I()for i in xrange(N)];dxy=((1,0),(0,1),(-1,0),(0,-1))
Vs=[[0]*N for i in xrange(N)];Vs[Sy][Sx]=V;Q=deque([(Sx,Sy,V,0)])
while Q:
	hx,hy,v,c=Q.popleft()
	if(hx,hy)==(Gx,Gy):print c;break
	if v<Vs[hy][hx]:continue
	for dx,dy in dxy:
		nx=hx+dx;ny=hy+dy
		if 0<=nx<N and 0<=ny<N and v-L[ny][nx]>Vs[ny][nx]:
			Vs[ny][nx]=v-L[ny][nx]
			Q.append((nx,ny,v-L[ny][nx],c+1))
else:print -1
0