結果

問題 No.20 砂漠のオアシス
ユーザー TawaraTawara
提出日時 2015-12-30 03:05:58
言語 Python2
(2.7.18)
結果
AC  
実行時間 282 ms / 5,000 ms
コード長 487 bytes
コンパイル時間 71 ms
コンパイル使用メモリ 6,648 KB
実行使用メモリ 8,932 KB
最終ジャッジ日時 2023-08-03 07:54:38
合計ジャッジ時間 2,426 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,176 KB
testcase_01 AC 14 ms
6,220 KB
testcase_02 AC 13 ms
6,164 KB
testcase_03 AC 24 ms
6,240 KB
testcase_04 AC 28 ms
6,232 KB
testcase_05 AC 282 ms
8,932 KB
testcase_06 AC 47 ms
7,040 KB
testcase_07 AC 217 ms
7,740 KB
testcase_08 AC 102 ms
7,204 KB
testcase_09 AC 198 ms
7,780 KB
testcase_10 AC 12 ms
6,216 KB
testcase_11 AC 13 ms
6,128 KB
testcase_12 AC 21 ms
6,124 KB
testcase_13 AC 23 ms
6,272 KB
testcase_14 AC 32 ms
6,396 KB
testcase_15 AC 27 ms
6,204 KB
testcase_16 AC 53 ms
6,520 KB
testcase_17 AC 41 ms
6,492 KB
testcase_18 AC 48 ms
6,476 KB
testcase_19 AC 53 ms
6,636 KB
testcase_20 AC 17 ms
6,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
I=lambda:map(int,raw_input().split())
N,V,x,y=I();o=(x-1,y-1);g=(N-1,N-1);L=[I()for i in range(N)]
dxy=((1,0),(0,1),(-1,0),(0,-1));D=[N*[0]for i in range(N)];D[0][0]=-V
Q=[];heappush(Q,(-V,(0,0),True))
while Q:
	v,h,f=heappop(Q)
	if h == g:print"YES";break
	for dx,dy in dxy:
		nx=h[0]+dx;ny=h[1]+dy
		if 0<=nx<N and 0<=ny<N:
			n=(nx,ny);nv=v+L[ny][nx]
			if f and n==o:nv*=2;f=False
			if nv<D[ny][nx]:D[ny][nx]=nv;heappush(Q,(nv,n,f))
else:print"NO"
0