結果
| 問題 | No.20 砂漠のオアシス | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2019-10-25 14:36:02 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,305 bytes | 
| コンパイル時間 | 96 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 14,080 KB | 
| 最終ジャッジ日時 | 2024-07-19 17:07:20 | 
| 合計ジャッジ時間 | 5,042 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 16 WA * 5 | 
ソースコード
from heapq import heappush, heappop
from collections import defaultdict
N, V, X, Y = map(int, input().split())
X -= 1
Y -= 1
L = [list(map(int, input().split())) for _ in range(N)]
minDistFromOrigin = [[float('inf')] * N for _ in range(N)]
minDistFromOasis = [[float('inf')] * N for _ in range(N)]
que = [(0, 0, 0)]
while que:
    d, x, y = heappop(que)
    if minDistFromOrigin[x][y] <= d:
        continue
    minDistFromOrigin[x][y] = d
    for nx in [x - 1, x + 1]:
        if 0 <= nx < N:
            heappush(que, (d + L[nx][y], nx, y))
    for ny in [y - 1, y + 1]:
        if 0 <= ny < N:
            heappush(que, (d + L[x][ny], x, ny))
dist = minDistFromOrigin[N - 1][N - 1]
if 0 <= X < N and 0 <= Y < N:
    que = [(0, X, Y)]
    while que:
        d, x, y = heappop(que)
        if minDistFromOasis[x][y] <= d:
            continue
        minDistFromOasis[x][y] = d
        for nx in [x - 1, x + 1]:
            if 0 <= nx < N:
                heappush(que, (d + L[nx][y], nx, y))
        for ny in [y - 1, y + 1]:
            if 0 <= ny < N:
                heappush(que, (d + L[x][ny], x, ny))
    dist = min(
        dist,
        minDistFromOrigin[X][Y] + minDistFromOasis[N - 1][N - 1] - (V - minDistFromOrigin[X][Y])
    )
if dist < V:
    print('YES')
else:
    print('NO')
            
            
            
        