結果

問題 No.20 砂漠のオアシス
ユーザー 👑 colognecologne
提出日時 2022-01-22 13:28:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 599 ms / 5,000 ms
コード長 985 bytes
コンパイル時間 461 ms
コンパイル使用メモリ 87,232 KB
実行使用メモリ 84,284 KB
最終ジャッジ日時 2023-08-18 06:26:28
合計ジャッジ時間 6,451 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,432 KB
testcase_01 AC 75 ms
71,124 KB
testcase_02 AC 80 ms
75,964 KB
testcase_03 AC 144 ms
78,196 KB
testcase_04 AC 182 ms
79,244 KB
testcase_05 AC 499 ms
84,284 KB
testcase_06 AC 198 ms
79,344 KB
testcase_07 AC 599 ms
83,580 KB
testcase_08 AC 237 ms
80,184 KB
testcase_09 AC 558 ms
83,952 KB
testcase_10 AC 73 ms
71,312 KB
testcase_11 AC 72 ms
71,328 KB
testcase_12 AC 161 ms
78,220 KB
testcase_13 AC 162 ms
78,828 KB
testcase_14 AC 180 ms
78,416 KB
testcase_15 AC 171 ms
78,532 KB
testcase_16 AC 241 ms
79,832 KB
testcase_17 AC 210 ms
79,364 KB
testcase_18 AC 215 ms
78,840 KB
testcase_19 AC 240 ms
79,180 KB
testcase_20 AC 138 ms
77,560 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