結果

問題 No.20 砂漠のオアシス
ユーザー brthyyjpbrthyyjp
提出日時 2021-11-10 01:54:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,447 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 81,792 KB
最終ジャッジ日時 2024-04-30 00:59:21
合計ジャッジ時間 3,765 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,736 KB
testcase_01 AC 46 ms
53,504 KB
testcase_02 AC 44 ms
53,120 KB
testcase_03 AC 102 ms
76,928 KB
testcase_04 AC 136 ms
77,428 KB
testcase_05 AC 281 ms
81,792 KB
testcase_06 AC 146 ms
81,664 KB
testcase_07 AC 260 ms
81,408 KB
testcase_08 AC 139 ms
81,024 KB
testcase_09 AC 234 ms
81,152 KB
testcase_10 WA -
testcase_11 AC 43 ms
52,992 KB
testcase_12 WA -
testcase_13 AC 116 ms
77,312 KB
testcase_14 AC 138 ms
77,524 KB
testcase_15 AC 132 ms
76,928 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 151 ms
78,036 KB
testcase_20 AC 115 ms
76,740 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, h, ox, oy = map(int, input().split())
ox, oy = ox-1, oy-1
L = [list(map(int, input().split())) for i in range(n)]
dp = [[-1]*2 for i in range(n*n)]
dp[0][0] = h
import heapq
q = []
q.append((-h, 0, 0))
heapq.heapify(q)
while q:
    cur_h, v, k = heapq.heappop(q)
    cur_h *= (-1)
    x, y = divmod(v, n)
    for dx, dy in (-1, 0), (1, 0), (0, -1), (0, 1):
        nx, ny = x+dx, y+dy
        if 0 <= nx < n and 0 <= ny < n:
            nv = nx*n+ny
            if cur_h-L[nx][ny] <= 0:
                continue
            if (nx, ny) != (ox, oy):
                if dp[nv][k] < cur_h-L[nx][ny]:
                    dp[nv][k] = cur_h-L[nx][ny]
                    heapq.heappush(q, (-dp[nv][k], nv, k))
            else:
                if k == 0:
                    if dp[nv][k+1] < 2*(cur_h-L[nx][ny]):
                        dp[nv][k+1] = 2*(cur_h-L[nx][ny])
                        heapq.heappush(q, (-dp[nv][k+1], nv, k+1))
                    if dp[nv][k] < cur_h-L[nx][ny]:
                        dp[nv][k] = cur_h-L[nx][ny]
                        heapq.heappush(q, (-dp[nv][k], nv, k))
                else:
                    if dp[nv][k] < cur_h-L[nx][ny]:
                        dp[nv][k] = cur_h-L[nx][ny]
                        heapq.heappush(q, (-dp[nv][k], nv, k))
ans = max(dp[-1])
if ans <= 0:
    print('NO')
else:
    print('YES')
0