結果

問題 No.20 砂漠のオアシス
ユーザー OKCH3COOHOKCH3COOH
提出日時 2019-10-25 15:07:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 626 ms / 5,000 ms
コード長 903 bytes
コンパイル時間 1,011 ms
コンパイル使用メモリ 10,924 KB
実行使用メモリ 17,516 KB
最終ジャッジ日時 2023-09-27 01:27:18
合計ジャッジ時間 4,716 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
8,584 KB
testcase_01 AC 19 ms
8,584 KB
testcase_02 AC 19 ms
8,596 KB
testcase_03 AC 38 ms
8,996 KB
testcase_04 AC 59 ms
9,292 KB
testcase_05 AC 366 ms
17,516 KB
testcase_06 AC 77 ms
9,828 KB
testcase_07 AC 626 ms
16,992 KB
testcase_08 AC 164 ms
10,704 KB
testcase_09 AC 544 ms
16,400 KB
testcase_10 AC 18 ms
8,516 KB
testcase_11 AC 18 ms
8,528 KB
testcase_12 AC 43 ms
9,184 KB
testcase_13 AC 41 ms
9,056 KB
testcase_14 AC 68 ms
9,624 KB
testcase_15 AC 59 ms
9,248 KB
testcase_16 AC 143 ms
10,348 KB
testcase_17 AC 102 ms
9,520 KB
testcase_18 AC 117 ms
10,292 KB
testcase_19 AC 141 ms
10,304 KB
testcase_20 AC 29 ms
8,772 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[y][nx] > 0:
            heappush(que, (-(life - L[y][nx]), nx, y, usedO))

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

print('NO')
0