結果

問題 No.20 砂漠のオアシス
ユーザー Mao-betaMao-beta
提出日時 2024-02-29 13:52:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 254 ms / 5,000 ms
コード長 1,848 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 79,876 KB
最終ジャッジ日時 2024-02-29 13:52:15
合計ジャッジ時間 4,457 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
57,828 KB
testcase_01 AC 46 ms
57,828 KB
testcase_02 AC 52 ms
57,828 KB
testcase_03 AC 103 ms
76,944 KB
testcase_04 AC 113 ms
77,172 KB
testcase_05 AC 254 ms
79,876 KB
testcase_06 AC 122 ms
78,428 KB
testcase_07 AC 227 ms
78,176 KB
testcase_08 AC 135 ms
78,048 KB
testcase_09 AC 247 ms
78,816 KB
testcase_10 AC 49 ms
57,828 KB
testcase_11 AC 50 ms
57,828 KB
testcase_12 AC 107 ms
76,932 KB
testcase_13 AC 101 ms
77,060 KB
testcase_14 AC 113 ms
77,040 KB
testcase_15 AC 109 ms
77,044 KB
testcase_16 AC 125 ms
77,440 KB
testcase_17 AC 121 ms
77,208 KB
testcase_18 AC 149 ms
77,292 KB
testcase_19 AC 129 ms
77,436 KB
testcase_20 AC 93 ms
76,796 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math
import bisect
from heapq import heapify, heappop, heappush
from collections import deque, defaultdict, Counter
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
MOD99 = 998244353

input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
SMI = lambda: input().split()
SLI = lambda: list(SMI())
EI = lambda m: [NLI() for _ in range(m)]


def main():
    N, V, ow, oh = NMI()
    L = EI(N)
    ow, oh = ow-1, oh-1

    hq = []
    hq.append([-V, 0, 0, 0])
    seen = [[[-1] * N for _ in range(N)] for _ in range(2)]
    seen[0][0][0] = V

    DH = [0, 0, 1, -1]
    DW = [1, -1, 0, 0]



    while hq:
        now_v, now_h, now_w, now_o = heappop(hq)
        now_v *= -1
        # print(now_v, now_h, now_w, now_o)
        if seen[now_o][now_h][now_w] > now_v:
            continue

        if now_h == oh and now_w == ow and now_o == 0:
            now_v *= 2
            now_o = 1
            seen[now_o][now_h][now_w] = now_v
        if now_h == N-1 and now_w == N-1:
            print("YES")
            # print(*seen, sep="\n")
            return

        for dh, dw in zip(DH, DW):
            goto_h = now_h + dh
            goto_w = now_w + dw
            goto_o = now_o

            if goto_h < 0 or goto_h >= N or goto_w < 0 or goto_w >= N:
                continue
            goto_v = now_v - L[goto_h][goto_w]
            if goto_v <= 0:
                continue
            if seen[goto_o][goto_h][goto_w] >= goto_v:
                continue

            heappush(hq, [-goto_v, goto_h, goto_w, goto_o])
            seen[goto_o][goto_h][goto_w] = goto_v


    print("NO")


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