結果

問題 No.20 砂漠のオアシス
ユーザー takakintakakin
提出日時 2020-05-25 21:29:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,082 bytes
コンパイル時間 181 ms
コンパイル使用メモリ 10,992 KB
実行使用メモリ 20,632 KB
最終ジャッジ日時 2023-08-03 04:26:59
合計ジャッジ時間 3,880 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,360 KB
testcase_01 AC 17 ms
8,316 KB
testcase_02 AC 18 ms
8,328 KB
testcase_03 AC 33 ms
8,984 KB
testcase_04 AC 34 ms
9,076 KB
testcase_05 AC 274 ms
17,852 KB
testcase_06 AC 322 ms
20,456 KB
testcase_07 AC 323 ms
20,324 KB
testcase_08 AC 329 ms
20,496 KB
testcase_09 AC 324 ms
20,632 KB
testcase_10 WA -
testcase_11 AC 17 ms
8,364 KB
testcase_12 WA -
testcase_13 AC 31 ms
8,864 KB
testcase_14 AC 45 ms
9,372 KB
testcase_15 AC 36 ms
9,008 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 24 ms
8,536 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=lambda: sys.stdin.readline().rstrip()
n,v,ox,oy=map(int,input().split())
L=[[int(i) for i in input().split()] for _ in range(n)]
nn=n**2
D=((1,0),(0,1),(-1,0),(0,-1))
edge=[[] for i in range(nn)]
for i in range(nn):
  ix,iy=i//n,i%n
  for dx,dy in D:
    if 0<=ix+dx<n and 0<=iy+dy<n:
      edge[i].append(L[ix+dx][iy+dy]*10**6+(ix+dx)*n+iy+dy)

import heapq
def dijkstra_heap(s):
  d=[float("inf")]*nn
  used=[True]*nn
  d[s]=0
  used[s]=False
  edgelist=[]
  for e in edge[s]:
    heapq.heappush(edgelist,e)
  while edgelist:
    minedge=heapq.heappop(edgelist)
    minedge_cost=minedge//(10**6)
    minedge_v=minedge%(10**6)
    if not used[minedge_v]:
      continue
    d[minedge_v] = minedge_cost
    used[minedge_v] = False
    for e in edge[minedge_v]:
      e_cost=e//(10**6)
      e_v=e%(10**6)
      if used[e_v]:
        heapq.heappush(edgelist,e+minedge_cost*10**6)
  return d

D1=dijkstra_heap(0)
D2=dijkstra_heap((ox-1)*n+oy)

if D1[-1]<v:
  print("YES")
elif D1[(ox-1)*n+oy-1]<v and D2[-1]<2*(v-D1[(ox-1)*n+oy-1]):
  print("YES")
else:
  print("NO")
0