結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
52,352 KB
testcase_01 AC 46 ms
53,120 KB
testcase_02 AC 45 ms
53,120 KB
testcase_03 AC 103 ms
76,928 KB
testcase_04 AC 146 ms
77,648 KB
testcase_05 AC 273 ms
81,792 KB
testcase_06 AC 148 ms
81,408 KB
testcase_07 AC 266 ms
81,560 KB
testcase_08 AC 133 ms
80,640 KB
testcase_09 AC 234 ms
81,448 KB
testcase_10 WA -
testcase_11 AC 42 ms
52,480 KB
testcase_12 WA -
testcase_13 AC 124 ms
76,720 KB
testcase_14 AC 147 ms
77,564 KB
testcase_15 AC 139 ms
77,592 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 154 ms
78,116 KB
testcase_20 AC 112 ms
76,416 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 = [[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 k == 0:
                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))
                    if nx == ox and ny == oy:
                        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))

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