結果

問題 No.20 砂漠のオアシス
ユーザー brthyyjpbrthyyjp
提出日時 2021-11-10 02:14:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 285 ms / 5,000 ms
コード長 1,279 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 82,240 KB
最終ジャッジ日時 2024-04-30 01:12:54
合計ジャッジ時間 3,920 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,480 KB
testcase_01 AC 45 ms
52,864 KB
testcase_02 AC 46 ms
53,120 KB
testcase_03 AC 107 ms
77,184 KB
testcase_04 AC 142 ms
77,816 KB
testcase_05 AC 285 ms
82,240 KB
testcase_06 AC 149 ms
81,280 KB
testcase_07 AC 261 ms
81,280 KB
testcase_08 AC 147 ms
80,768 KB
testcase_09 AC 252 ms
81,416 KB
testcase_10 AC 45 ms
52,864 KB
testcase_11 AC 44 ms
52,864 KB
testcase_12 AC 126 ms
76,800 KB
testcase_13 AC 118 ms
77,056 KB
testcase_14 AC 140 ms
77,152 KB
testcase_15 AC 128 ms
77,112 KB
testcase_16 AC 152 ms
78,148 KB
testcase_17 AC 140 ms
77,236 KB
testcase_18 AC 163 ms
78,056 KB
testcase_19 AC 160 ms
78,276 KB
testcase_20 AC 109 ms
76,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

n, h, oy, ox = map(int, input().split())
ox, oy = ox-1, oy-1
L = [list(map(int, input().split())) for i in range(n)]
dp = [[0]*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))
                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