結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,812 KB
testcase_01 AC 11 ms
6,944 KB
testcase_02 AC 10 ms
6,948 KB
testcase_03 AC 21 ms
6,940 KB
testcase_04 AC 20 ms
6,940 KB
testcase_05 AC 356 ms
9,648 KB
testcase_06 AC 258 ms
8,064 KB
testcase_07 AC 257 ms
8,064 KB
testcase_08 AC 302 ms
8,064 KB
testcase_09 AC 257 ms
8,064 KB
testcase_10 AC 11 ms
6,940 KB
testcase_11 AC 10 ms
6,940 KB
testcase_12 AC 20 ms
6,940 KB
testcase_13 AC 24 ms
6,944 KB
testcase_14 AC 35 ms
6,944 KB
testcase_15 AC 27 ms
6,940 KB
testcase_16 AC 62 ms
6,944 KB
testcase_17 AC 49 ms
6,940 KB
testcase_18 AC 57 ms
6,944 KB
testcase_19 AC 64 ms
6,940 KB
testcase_20 AC 16 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
I=lambda:map(int,raw_input().split())
N,V,x,y=I();s=(0,0);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))
def d(s,g):
	Q=[];D=[N*[100000]for i in range(N)]
	D[s[1]][s[0]]=0
	heappush(Q,(0,s))
	while Q:
		c,h=heappop(Q)
		if h == g:break
		for dx,dy in dxy:
			nx=h[0]+dx;ny=h[1]+dy
			if 0<=nx<N and 0<=ny<N and c+L[ny][nx]<D[ny][nx]:
				D[ny][nx]=nc=c+L[ny][nx];heappush(Q,(nc,(nx,ny)))
	return D[g[1]][g[0]]
print["NO","YES"][V>d(s,g)or(o!=(-1,-1) and(V-d(s,o))*2>d(o,g))]
0