結果

問題 No.20 砂漠のオアシス
ユーザー qibqib
提出日時 2023-01-19 01:06:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 838 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 82,780 KB
最終ジャッジ日時 2023-09-02 18:07:47
合計ジャッジ時間 5,181 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,108 KB
testcase_01 AC 74 ms
71,236 KB
testcase_02 AC 70 ms
71,252 KB
testcase_03 AC 115 ms
77,784 KB
testcase_04 AC 137 ms
78,336 KB
testcase_05 AC 332 ms
82,780 KB
testcase_06 AC 256 ms
79,388 KB
testcase_07 AC 257 ms
79,488 KB
testcase_08 AC 171 ms
78,768 KB
testcase_09 AC 253 ms
79,412 KB
testcase_10 WA -
testcase_11 AC 72 ms
71,240 KB
testcase_12 WA -
testcase_13 AC 147 ms
78,936 KB
testcase_14 AC 146 ms
78,748 KB
testcase_15 AC 144 ms
78,680 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 156 ms
78,520 KB
testcase_20 AC 117 ms
77,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

INF = 1 << 60

n, v, ox, oy = map(int, input().split())
ox -= 1
oy -= 1
l = [list(map(int, input().split())) for _ in range(n)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def cost(sx, sy, gx, gy):
  dist = [[INF for _ in range(n)] for _ in range(n)]
  dist[sx][sy] = 0
  hp = [(0, sx, sy)]
  while len(hp) > 0:
    cd, cx, cy = heapq.heappop(hp)
    if cd > dist[cx][cy]:
      continue

    for i in range(4):
      nx = cx + dx[i]
      ny = cy + dy[i]
      if nx < 0 or nx >= n or ny < 0 or ny >= n:
        continue
      if dist[nx][ny] > dist[cx][cy] + l[nx][ny]:
        dist[nx][ny] = dist[cx][cy] + l[nx][ny]
        heapq.heappush(hp, (dist[nx][ny], nx, ny))

  return dist[gx][gy]

if ox == -1 and oy == -1:
  rest = v - cost(0, 0, n - 1, n - 1)
  if rest <= 0:
    print("NO")
  else:
    print("YES")
else:
  rest = v - cost(0, 0, ox, oy)
  if rest <= 0:
    print("NO")
  else:
    rest = 2 * rest - cost(ox, oy, n - 1, n - 1)
    if rest <= 0:
      print("NO")
    else:
      print("YES")
0