結果

問題 No.20 砂漠のオアシス
ユーザー pluto77
提出日時 2018-07-29 13:03:33
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 9,216 KB
最終ジャッジ日時 2024-07-16 02:53:30
合計ジャッジ時間 3,048 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki20
import heapq,sys

direction=[(1,0),(0,1),(-1,0),(0,-1)]

def dijkstra(sx,sy,l):
 dist=[[float('inf')]*len(l) for i in xrange(len(l))]
 dist[sx][sy]=0
 queue=[(0,sx,sy)]
 while queue:
  d,x,y=heapq.heappop(queue)
  if dist[y][x]<d:
   continue
  for dx,dy in direction:
   nx=x+dx
   ny=y+dy
   if 0<=nx<len(l) and 0<=ny<len(l) and dist[ny][nx]>d+l[ny][nx]:
     dist[ny][nx]=d+l[ny][nx]
     heapq.heappush(queue,(dist[ny][nx],nx,ny))
 return dist


n,v,xx,yy=map(int,raw_input().split())
l=[map(int,raw_input().split()) for i in xrange(n)]
xx-=1
yy-=1
dist=dijkstra(0,0,l)
if dist[n-1][n-1]<v:                                                                                                                                                                                                                                                 
 print 'YES'
 sys.exit()
if xx>=0 and dist[yy][xx]<v:
 v=(v-dist[yy][xx])*2
 dist=dijkstra(xx,yy,l)
 if dist[n-1][n-1]<v:
  print 'YES'
  sys.exit()
print 'NO'
0