結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,480 KB
testcase_01 AC 43 ms
53,248 KB
testcase_02 AC 44 ms
53,248 KB
testcase_03 AC 99 ms
76,852 KB
testcase_04 AC 126 ms
77,564 KB
testcase_05 AC 264 ms
82,048 KB
testcase_06 AC 133 ms
81,476 KB
testcase_07 AC 251 ms
81,216 KB
testcase_08 AC 128 ms
80,976 KB
testcase_09 AC 227 ms
81,360 KB
testcase_10 WA -
testcase_11 AC 41 ms
53,248 KB
testcase_12 WA -
testcase_13 AC 110 ms
76,852 KB
testcase_14 AC 125 ms
77,728 KB
testcase_15 AC 114 ms
76,860 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 143 ms
77,716 KB
testcase_20 AC 105 ms
76,384 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))
                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