結果

問題 No.20 砂漠のオアシス
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-10-25 14:23:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 903 bytes
コンパイル時間 90 ms
コンパイル使用メモリ 10,916 KB
実行使用メモリ 17,320 KB
最終ジャッジ日時 2023-09-26 22:20:28
合計ジャッジ時間 4,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
8,560 KB
testcase_01 AC 21 ms
8,584 KB
testcase_02 AC 20 ms
8,728 KB
testcase_03 AC 39 ms
8,960 KB
testcase_04 AC 60 ms
9,360 KB
testcase_05 AC 381 ms
17,320 KB
testcase_06 AC 70 ms
9,652 KB
testcase_07 AC 629 ms
16,864 KB
testcase_08 AC 167 ms
10,776 KB
testcase_09 AC 480 ms
16,288 KB
testcase_10 WA -
testcase_11 AC 19 ms
8,656 KB
testcase_12 WA -
testcase_13 AC 41 ms
9,016 KB
testcase_14 AC 76 ms
9,476 KB
testcase_15 AC 64 ms
9,292 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 148 ms
10,392 KB
testcase_20 AC 34 ms
8,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
from collections import defaultdict

N, V, X, Y = map(int, input().split())
X -= 1
Y -= 1

L = [list(map(int, input().split())) for _ in range(N)]

que = [(-V, 0, 0, False)]  # life, x, y, usedO
maxLife = defaultdict(lambda : -float('inf'))

while que:
    life, x, y, usedO = heappop(que)
    life *= -1

    if x == X and y == Y and not usedO:
        life *= 2
        usedO = True

    if life <= 0:
        continue

    if x == y == N - 1:
        print('YES')
        exit()

    if maxLife[(x, y, usedO)] >= life:
        continue
    maxLife[(x, y, usedO)] = life

    for nx in [x - 1, x + 1]:
        if 0 <= nx < N and life - L[nx][y] > 0:
            heappush(que, (-(life - L[nx][y]), nx, y, usedO))

    for ny in [y - 1, y + 1]:
        if 0 <= ny < N and life - L[x][ny] > 0:
            heappush(que, (-(life - L[x][ny]), x, ny, usedO))

print('NO')
0