結果

問題 No.20 砂漠のオアシス
ユーザー lloyzlloyz
提出日時 2023-10-06 01:00:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 303 ms / 5,000 ms
コード長 872 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 80,772 KB
最終ジャッジ日時 2023-10-06 01:00:12
合計ジャッジ時間 5,139 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
71,392 KB
testcase_01 AC 87 ms
71,252 KB
testcase_02 AC 83 ms
71,140 KB
testcase_03 AC 130 ms
78,288 KB
testcase_04 AC 163 ms
78,476 KB
testcase_05 AC 303 ms
80,772 KB
testcase_06 AC 177 ms
79,980 KB
testcase_07 AC 234 ms
80,200 KB
testcase_08 AC 169 ms
79,780 KB
testcase_09 AC 232 ms
79,340 KB
testcase_10 AC 81 ms
71,164 KB
testcase_11 AC 86 ms
71,356 KB
testcase_12 AC 137 ms
78,448 KB
testcase_13 AC 134 ms
78,036 KB
testcase_14 AC 169 ms
79,248 KB
testcase_15 AC 153 ms
78,836 KB
testcase_16 AC 185 ms
79,208 KB
testcase_17 AC 168 ms
78,880 KB
testcase_18 AC 192 ms
79,352 KB
testcase_19 AC 185 ms
79,264 KB
testcase_20 AC 118 ms
77,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop, heappush

n, v, oj, oi = map(int, input().split())
oj -= 1
oi -= 1
L = [list(map(int, input().split())) for _ in range(n)]

Directions = [(1, 0), (0, 1), (-1, 0), (0, -1)]
DP = [[0 for _ in range(n)] for _ in range(n)]
DP[0][0] = v
H = [(-v, 0, 0, 0)]
while H:
    cv, ci, cj, use = heappop(H)
    cv *= -1
    if cv < DP[ci][cj]:
        continue
    if ci == n - 1 and cj == n - 1:
        break
    for di, dj in Directions:
        ni, nj = ci + di, cj + dj
        nuse = use
        if 0 <= ni < n and 0 <= nj < n:
            nv = cv - L[ni][nj]
            if not use and ni == oi and nj == oj:
                nv *= 2
                nuse = True
            if nv <= DP[ni][nj]:
                continue
            DP[ni][nj] = nv
            heappush(H, (-nv, ni, nj, nuse))
if DP[-1][-1] == 0:
    print("NO")
else:
    print("YES")
0