結果

問題 No.20 砂漠のオアシス
ユーザー pluto77pluto77
提出日時 2018-07-29 13:03:33
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 6,696 KB
実行使用メモリ 8,632 KB
最終ジャッジ日時 2023-09-23 02:31:32
合計ジャッジ時間 3,053 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,120 KB
testcase_01 AC 14 ms
6,092 KB
testcase_02 AC 13 ms
6,184 KB
testcase_03 AC 20 ms
6,212 KB
testcase_04 AC 20 ms
6,256 KB
testcase_05 AC 264 ms
8,240 KB
testcase_06 AC 251 ms
8,596 KB
testcase_07 AC 254 ms
8,616 KB
testcase_08 AC 139 ms
7,740 KB
testcase_09 AC 247 ms
8,632 KB
testcase_10 AC 13 ms
6,180 KB
testcase_11 WA -
testcase_12 AC 22 ms
6,248 KB
testcase_13 AC 25 ms
6,224 KB
testcase_14 AC 33 ms
6,316 KB
testcase_15 AC 27 ms
6,268 KB
testcase_16 AC 58 ms
6,636 KB
testcase_17 AC 44 ms
6,424 KB
testcase_18 AC 51 ms
6,548 KB
testcase_19 AC 58 ms
6,492 KB
testcase_20 AC 18 ms
6,208 KB
権限があれば一括ダウンロードができます

ソースコード

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