結果

問題 No.20 砂漠のオアシス
ユーザー TawaraTawara
提出日時 2015-12-30 03:05:58
言語 Python2
(2.7.18)
結果
AC  
実行時間 292 ms / 5,000 ms
コード長 487 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-04-21 06:48:25
合計ジャッジ時間 2,226 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,812 KB
testcase_01 AC 13 ms
6,940 KB
testcase_02 AC 13 ms
6,940 KB
testcase_03 AC 24 ms
6,944 KB
testcase_04 AC 28 ms
6,940 KB
testcase_05 AC 292 ms
9,600 KB
testcase_06 AC 48 ms
7,424 KB
testcase_07 AC 231 ms
8,064 KB
testcase_08 AC 108 ms
7,680 KB
testcase_09 AC 207 ms
8,064 KB
testcase_10 AC 12 ms
6,940 KB
testcase_11 AC 12 ms
6,940 KB
testcase_12 AC 21 ms
6,944 KB
testcase_13 AC 23 ms
6,940 KB
testcase_14 AC 34 ms
6,944 KB
testcase_15 AC 27 ms
6,944 KB
testcase_16 AC 56 ms
6,944 KB
testcase_17 AC 42 ms
6,940 KB
testcase_18 AC 50 ms
6,940 KB
testcase_19 AC 56 ms
6,944 KB
testcase_20 AC 17 ms
6,940 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