結果

問題 No.20 砂漠のオアシス
コンテスト
ユーザー Kude
提出日時 2020-09-04 04:39:55
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 948 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 159,088 KB
最終ジャッジ日時 2024-11-24 17:20:40
合計ジャッジ時間 73,964 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 8 WA * 2 TLE * 11
権限があれば一括ダウンロードができます

ソースコード

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]
def min_cost(sx, sy, gx, gy):
    dp = [[INF] * n for _ in range(n)]
    dp[sx][sy] = 0
    q = [(0, sx, sy)]
    while q:
        cost, x, y = q.pop()
        if cost > dp[x][y]:
            continue
        for k in range(4):
            nx = x + dx[k]
            ny = y + dy[k]
            if not (0 <= nx < n and 0 <= ny < n):
                continue
            nc = cost + l[nx][ny]
            if nc < dp[nx][ny]:
                dp[nx][ny] = nc
                heappush(q, (nc, nx, ny))
    return dp[gx][gy]
ok = False
if min_cost(0, 0, n-1, n-1) < v:
    ok = True
if ox >= 0:
    nv = v - min_cost(0, 0, ox, oy)
    if nv >= 1:
        nv *= 2
        if min_cost(ox, oy, n-1, n-1) < nv:
            ok = True
print('YES' if ok else 'NO')
0