結果
問題 | No.20 砂漠のオアシス |
ユーザー | Mao-beta |
提出日時 | 2024-02-29 13:52:10 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 223 ms / 5,000 ms |
コード長 | 1,848 bytes |
コンパイル時間 | 320 ms |
コンパイル使用メモリ | 82,420 KB |
実行使用メモリ | 80,824 KB |
最終ジャッジ日時 | 2024-09-29 12:41:23 |
合計ジャッジ時間 | 3,134 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 21 |
ソースコード
import sysimport mathimport bisectfrom heapq import heapify, heappop, heappushfrom collections import deque, defaultdict, Counterfrom functools import lru_cachefrom itertools import accumulate, combinations, permutations, productsys.setrecursionlimit(1000000)MOD = 10 ** 9 + 7MOD99 = 998244353input = 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-1hq = []hq.append([-V, 0, 0, 0])seen = [[[-1] * N for _ in range(N)] for _ in range(2)]seen[0][0][0] = VDH = [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:continueif now_h == oh and now_w == ow and now_o == 0:now_v *= 2now_o = 1seen[now_o][now_h][now_w] = now_vif now_h == N-1 and now_w == N-1:print("YES")# print(*seen, sep="\n")returnfor dh, dw in zip(DH, DW):goto_h = now_h + dhgoto_w = now_w + dwgoto_o = now_oif goto_h < 0 or goto_h >= N or goto_w < 0 or goto_w >= N:continuegoto_v = now_v - L[goto_h][goto_w]if goto_v <= 0:continueif seen[goto_o][goto_h][goto_w] >= goto_v:continueheappush(hq, [-goto_v, goto_h, goto_w, goto_o])seen[goto_o][goto_h][goto_w] = goto_vprint("NO")if __name__ == "__main__":main()