結果

問題 No.20 砂漠のオアシス
ユーザー maspymaspy
提出日時 2020-03-20 02:59:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 160 ms / 5,000 ms
コード長 1,321 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 10,956 KB
実行使用メモリ 19,136 KB
最終ジャッジ日時 2023-08-20 21:22:52
合計ジャッジ時間 2,499 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,384 KB
testcase_01 AC 17 ms
8,388 KB
testcase_02 AC 17 ms
8,424 KB
testcase_03 AC 21 ms
8,540 KB
testcase_04 AC 22 ms
8,500 KB
testcase_05 AC 132 ms
15,948 KB
testcase_06 AC 158 ms
18,928 KB
testcase_07 AC 158 ms
18,828 KB
testcase_08 AC 160 ms
19,136 KB
testcase_09 AC 159 ms
18,928 KB
testcase_10 AC 17 ms
8,096 KB
testcase_11 AC 17 ms
8,356 KB
testcase_12 AC 21 ms
8,488 KB
testcase_13 AC 23 ms
8,668 KB
testcase_14 AC 28 ms
9,268 KB
testcase_15 AC 26 ms
8,792 KB
testcase_16 AC 42 ms
10,424 KB
testcase_17 AC 34 ms
9,572 KB
testcase_18 AC 38 ms
10,100 KB
testcase_19 AC 43 ms
10,372 KB
testcase_20 AC 20 ms
8,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/ python3.8
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heappop, heappush

N, V, Oy, Ox = map(int, readline().split())
Ox -= 1
Oy -= 1
oasis = Ox * N + Oy
start = 0
goal = N * N - 1
L = tuple(map(int, read().split()))
graph = [[] for _ in range(N * N)]
for i in range(N * N):
    x, y = divmod(i, N)
    if x:
        j = i - N
        graph[i].append(j)
        graph[j].append(i)
    if y:
        j = i - 1
        graph[i].append(j)
        graph[j].append(i)


def dijkstra(start):
    INF = 10 ** 9
    dist = [INF] * (N * N)
    dist[start] = 0
    q = [start]
    mask = (1 << 20) - 1
    while q:
        x = heappop(q)
        dv = x >> 20
        v = x & mask
        if dist[v] < dv:
            continue
        for w in graph[v]:
            dw = dv + L[w]
            if dist[w] <= dw:
                continue
            dist[w] = dw
            heappush(q, (dw << 20) + w)
    return dist


def solve():
    global V
    dist1 = dijkstra(start)
    if dist1[goal] < V:
        return True
    if Ox == -1:
        return False
    dist2 = dijkstra(oasis)
    V -= dist1[oasis]
    if V <= 0:
        return False
    V *= 2
    V -= dist2[goal]
    return V > 0


print('YES' if solve() else 'NO')
0