結果
問題 |
No.20 砂漠のオアシス
|
ユーザー |
![]() |
提出日時 | 2015-12-30 02:37:05 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 376 ms / 5,000 ms |
コード長 | 543 bytes |
コンパイル時間 | 117 ms |
コンパイル使用メモリ | 6,912 KB |
実行使用メモリ | 9,648 KB |
最終ジャッジ日時 | 2024-10-13 05:31:15 |
合計ジャッジ時間 | 2,807 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
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))]