結果

問題 No.20 砂漠のオアシス
ユーザー KudeKude
提出日時 2020-09-04 05:50:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 800 bytes
コンパイル時間 565 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 84,156 KB
最終ジャッジ日時 2023-08-16 08:16:52
合計ジャッジ時間 5,213 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,432 KB
testcase_01 AC 74 ms
71,412 KB
testcase_02 AC 75 ms
71,432 KB
testcase_03 AC 123 ms
78,236 KB
testcase_04 AC 171 ms
79,916 KB
testcase_05 AC 283 ms
84,156 KB
testcase_06 AC 162 ms
82,556 KB
testcase_07 AC 282 ms
83,036 KB
testcase_08 AC 151 ms
82,452 KB
testcase_09 AC 258 ms
83,328 KB
testcase_10 WA -
testcase_11 AC 72 ms
71,316 KB
testcase_12 WA -
testcase_13 AC 142 ms
79,112 KB
testcase_14 AC 163 ms
79,200 KB
testcase_15 AC 163 ms
79,436 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 183 ms
79,772 KB
testcase_20 AC 122 ms
77,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, v, ox, oy = 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