結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
52,736 KB
testcase_01 AC 53 ms
53,120 KB
testcase_02 AC 50 ms
52,992 KB
testcase_03 AC 114 ms
76,800 KB
testcase_04 AC 136 ms
77,388 KB
testcase_05 AC 300 ms
82,048 KB
testcase_06 AC 143 ms
81,360 KB
testcase_07 AC 266 ms
81,664 KB
testcase_08 AC 138 ms
80,896 KB
testcase_09 AC 234 ms
81,536 KB
testcase_10 WA -
testcase_11 AC 44 ms
52,880 KB
testcase_12 WA -
testcase_13 AC 115 ms
76,928 KB
testcase_14 AC 133 ms
77,688 KB
testcase_15 AC 130 ms
76,984 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 152 ms
78,288 KB
testcase_20 AC 111 ms
76,800 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 == ox and ny == oy:
                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))
            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))

t = (n-1)*n+n-1
if dp[t][0] > 0 or dp[t][1] > 0:
    print('YES')
else:
    print('NO')
0