結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 28 ms
10,752 KB
testcase_02 AC 29 ms
10,752 KB
testcase_03 AC 45 ms
11,264 KB
testcase_04 AC 48 ms
11,392 KB
testcase_05 AC 294 ms
20,216 KB
testcase_06 AC 350 ms
22,968 KB
testcase_07 AC 353 ms
22,976 KB
testcase_08 AC 349 ms
23,100 KB
testcase_09 AC 354 ms
22,952 KB
testcase_10 WA -
testcase_11 AC 29 ms
10,752 KB
testcase_12 WA -
testcase_13 AC 43 ms
11,264 KB
testcase_14 AC 58 ms
11,904 KB
testcase_15 AC 48 ms
11,520 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 90 ms
13,056 KB
testcase_20 AC 37 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-1)

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