結果

問題 No.20 砂漠のオアシス
ユーザー 👑 colognecologne
提出日時 2022-01-22 13:28:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 586 ms / 5,000 ms
コード長 985 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 82,664 KB
最終ジャッジ日時 2024-05-05 12:27:58
合計ジャッジ時間 5,121 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,352 KB
testcase_01 AC 42 ms
52,864 KB
testcase_02 AC 45 ms
58,752 KB
testcase_03 AC 114 ms
76,360 KB
testcase_04 AC 150 ms
77,720 KB
testcase_05 AC 469 ms
82,664 KB
testcase_06 AC 163 ms
78,080 KB
testcase_07 AC 586 ms
82,172 KB
testcase_08 AC 212 ms
78,976 KB
testcase_09 AC 539 ms
82,348 KB
testcase_10 AC 41 ms
52,992 KB
testcase_11 AC 41 ms
52,608 KB
testcase_12 AC 131 ms
76,744 KB
testcase_13 AC 127 ms
76,992 KB
testcase_14 AC 151 ms
77,028 KB
testcase_15 AC 141 ms
76,720 KB
testcase_16 AC 213 ms
78,140 KB
testcase_17 AC 181 ms
77,744 KB
testcase_18 AC 187 ms
77,680 KB
testcase_19 AC 212 ms
77,628 KB
testcase_20 AC 110 ms
76,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq

input = sys.stdin.readline


def main():
    N, V, Ox, Oy = map(int, input().split())
    L = [list(map(int, input().split())) for i in range(N)]

    vis = [[[False]*N for i in range(N)] for i in range(2)]
    Q = [(-V, 0, 0, False)]

    while len(Q) > 0:
        hp, r, c, oa = heapq.heappop(Q)
        hp = -hp
        if vis[1 if oa else 0][r][c]:
            continue
        if r == c == N-1:
            print('YES')
            return
        vis[1 if oa else 0][r][c] = True
        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            nr, nc = r + dx, c + dy
            if 0 <= nr < N and 0 <= nc < N:
                nhp = hp - L[nr][nc]
                if nhp > 0:
                    noa = oa
                    if not oa and (nr, nc) == (Oy-1, Ox-1):
                        noa = True
                        nhp *= 2
                    heapq.heappush(Q, (-nhp, nr, nc, noa))
    print('NO')


if __name__ == '__main__':
    main()
0