結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  tktk_snsn | 
| 提出日時 | 2020-12-24 04:20:42 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 234 ms / 5,000 ms | 
| コード長 | 1,060 bytes | 
| コンパイル時間 | 199 ms | 
| コンパイル使用メモリ | 81,920 KB | 
| 実行使用メモリ | 79,232 KB | 
| 最終ジャッジ日時 | 2024-09-21 16:47:23 | 
| 合計ジャッジ時間 | 3,348 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 21 | 
ソースコード
import heapq
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
inf = 10000
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]
N, V, oy, ox = map(int, input().split())
L = tuple(tuple(map(int, input().split())) for _ in range(N))
ox -= 1
oy -= 1
dist = [[inf] * N for _ in range(N)]
dist[0][0] = 0
que = [(0, 0, 0)]
while que:
    ds, x, y = heapq.heappop(que)
    if dist[x][y] < ds:
        continue
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        if nx < 0 or N <= nx or ny < 0 or N <= ny:
            continue
        cost = ds + L[nx][ny]
        if cost >= V:
            continue
        if dist[nx][ny] > cost:
            dist[nx][ny] = cost
            if (nx, ny) == (ox, oy):
                dist[nx][ny] -= (V - cost)
                ox = -1
                oy = -1
            heapq.heappush(que, (dist[nx][ny], nx, ny))
# if 1:
#     import numpy as np
#     print(np.array(dist))
if dist[N - 1][N - 1] < V:
    print("YES")
else:
    print("NO")
            
            
            
        