結果

問題 No.20 砂漠のオアシス
ユーザー 👑 rin204rin204
提出日時 2022-07-04 14:51:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 329 ms / 5,000 ms
コード長 990 bytes
コンパイル時間 1,169 ms
コンパイル使用メモリ 86,760 KB
実行使用メモリ 82,408 KB
最終ジャッジ日時 2023-08-20 22:00:15
合計ジャッジ時間 5,382 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
71,268 KB
testcase_01 AC 81 ms
71,036 KB
testcase_02 AC 79 ms
71,112 KB
testcase_03 AC 124 ms
77,472 KB
testcase_04 AC 121 ms
77,668 KB
testcase_05 AC 329 ms
82,408 KB
testcase_06 AC 270 ms
79,412 KB
testcase_07 AC 268 ms
79,340 KB
testcase_08 AC 189 ms
78,728 KB
testcase_09 AC 266 ms
79,372 KB
testcase_10 AC 79 ms
71,220 KB
testcase_11 AC 78 ms
71,276 KB
testcase_12 AC 143 ms
78,160 KB
testcase_13 AC 150 ms
78,276 KB
testcase_14 AC 159 ms
78,876 KB
testcase_15 AC 156 ms
78,528 KB
testcase_16 AC 178 ms
78,332 KB
testcase_17 AC 166 ms
78,864 KB
testcase_18 AC 174 ms
78,576 KB
testcase_19 AC 169 ms
78,304 KB
testcase_20 AC 128 ms
77,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

n, v, oy, ox = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
inf = 1 << 30
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]


def dijkstra(si, sj):
    dist = [[inf] * n for _ in range(n)]
    dist[si][sj] = 0
    hq = [(0, si, sj)]
    while hq:
        d, i, j = heappop(hq)
        if dist[i][j] < d:
            continue
        for di, dj in directions:
            ni = i + di
            nj = j + dj
            if ni == -1 or nj == -1 or ni == n or nj == n:
                continue
            tmp = d + L[ni][nj]
            if tmp < dist[ni][nj]:
                dist[ni][nj] = tmp
                heappush(hq, (tmp, ni, nj))
    return dist

dist = dijkstra(0, 0)
if dist[-1][-1] < v:
    print("YES")
    exit()
if ox == oy == 0:
    print("NO")
    exit()
ox -= 1
oy -= 1
v -= dist[ox][oy]

if v <= 0:
    print("NO")
    exit()
v *= 2
dist = dijkstra(ox, oy)
if dist[-1][-1] < v:
    print("YES")
else:
    print("NO")
0