結果

問題 No.20 砂漠のオアシス
ユーザー pluto77pluto77
提出日時 2018-07-29 13:21:25
言語 Python2
(2.7.18)
結果
AC  
実行時間 231 ms / 5,000 ms
コード長 1,000 bytes
コンパイル時間 418 ms
コンパイル使用メモリ 6,688 KB
実行使用メモリ 8,684 KB
最終ジャッジ日時 2023-09-23 02:59:20
合計ジャッジ時間 3,202 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 12 ms
6,176 KB
testcase_01 AC 13 ms
6,092 KB
testcase_02 AC 12 ms
6,144 KB
testcase_03 AC 18 ms
6,228 KB
testcase_04 AC 19 ms
6,244 KB
testcase_05 AC 231 ms
8,296 KB
testcase_06 AC 220 ms
8,684 KB
testcase_07 AC 219 ms
8,596 KB
testcase_08 AC 124 ms
7,724 KB
testcase_09 AC 220 ms
8,648 KB
testcase_10 AC 12 ms
6,136 KB
testcase_11 AC 13 ms
6,180 KB
testcase_12 AC 20 ms
6,308 KB
testcase_13 AC 21 ms
6,184 KB
testcase_14 AC 30 ms
6,292 KB
testcase_15 AC 25 ms
6,232 KB
testcase_16 AC 51 ms
6,628 KB
testcase_17 AC 40 ms
6,408 KB
testcase_18 AC 45 ms
6,544 KB
testcase_19 AC 53 ms
6,580 KB
testcase_20 AC 16 ms
6,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yuki20
import heapq,sys

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

def dijkstra(sx,sy,L):
 N=len(L)
 dist=[[float("inf")] * N for i in xrange(N)]
 dist[sy][sx]= 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<N and 0<=ny<N 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