結果

問題 No.20 砂漠のオアシス
ユーザー takakintakakin
提出日時 2020-05-25 21:28:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,081 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 23,232 KB
最終ジャッジ日時 2024-04-21 03:53:15
合計ジャッジ時間 3,814 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 45 ms
11,264 KB
testcase_04 AC 48 ms
11,392 KB
testcase_05 AC 287 ms
20,212 KB
testcase_06 AC 334 ms
22,960 KB
testcase_07 WA -
testcase_08 AC 346 ms
23,096 KB
testcase_09 AC 345 ms
22,980 KB
testcase_10 WA -
testcase_11 AC 29 ms
10,752 KB
testcase_12 WA -
testcase_13 AC 44 ms
11,264 KB
testcase_14 AC 56 ms
11,904 KB
testcase_15 AC 48 ms
11,648 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 93 ms
13,056 KB
testcase_20 AC 35 ms
11,008 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]<=v and D2[-1]<=2*(v-D1[(ox-1)*n+oy]):
  print("YES")
else:
  print("NO")
0