結果

問題 No.20 砂漠のオアシス
ユーザー Tawara
提出日時 2015-12-30 02:58:06
言語 Python2
(2.7.18)
結果
RE  
実行時間 -
コード長 484 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 7,040 KB
最終ジャッジ日時 2024-10-13 05:31:20
合計ジャッジ時間 1,194 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 21
権限があれば一括ダウンロードができます

ソースコード

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 xrange(N)]
dxy=((1,0),(0,1),(-1,0),(0,-1));D=[N*[0]for i in xrange(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,n,f)
else:print"NO"
0