結果

問題 No.20 砂漠のオアシス
ユーザー KudeKude
提出日時 2020-09-04 05:51:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 263 ms / 5,000 ms
コード長 800 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 82,560 KB
最終ジャッジ日時 2024-05-03 17:13:26
合計ジャッジ時間 3,793 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,992 KB
testcase_01 AC 39 ms
53,248 KB
testcase_02 AC 40 ms
52,480 KB
testcase_03 AC 93 ms
77,048 KB
testcase_04 AC 140 ms
77,936 KB
testcase_05 AC 263 ms
82,560 KB
testcase_06 AC 149 ms
81,280 KB
testcase_07 AC 254 ms
81,484 KB
testcase_08 AC 124 ms
81,000 KB
testcase_09 AC 240 ms
81,256 KB
testcase_10 AC 41 ms
52,864 KB
testcase_11 AC 40 ms
52,736 KB
testcase_12 AC 118 ms
77,500 KB
testcase_13 AC 115 ms
76,752 KB
testcase_14 AC 141 ms
78,460 KB
testcase_15 AC 135 ms
77,632 KB
testcase_16 AC 160 ms
78,728 KB
testcase_17 AC 145 ms
78,012 KB
testcase_18 AC 146 ms
78,164 KB
testcase_19 AC 152 ms
78,504 KB
testcase_20 AC 89 ms
76,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, v, oy, ox = map(int, input().split())
ox -= 1
oy -= 1
l = [list(map(int, input().split())) for _ in range(n)]

INF = 10 ** 18
from heapq import heappush, heappop
dx = [1,0,-1,0]
dy = [0,1,0,-1]
dp = [[[0, 0] for _ in range(n)] for _ in range(n)]
q = [(-v, 0, 0, 0)]
while q:
    vit, x, y, used = heappop(q)
    vit = -vit
    if vit < dp[x][y][used]:
        continue
    for k in range(4):
        nx, ny = x + dx[k], y + dy[k]
        if not (0 <= nx < n and 0 <= ny < n):
            continue
        nv = vit - l[nx][ny]
        if nv > dp[nx][ny][used]:
            dp[nx][ny][used] = nv
            heappush(q, (-nv, nx, ny, used))
    if not used and (x, y) == (ox, oy):
        dp[x][y][1] = vit * 2
        heappush(q, (-vit * 2, x, y, 1))
print('YES' if max(dp[n-1][n-1]) > 0 else 'NO')
0