結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-25 15:06:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 606 ms / 5,000 ms |
| コード長 | 1,293 bytes |
| コンパイル時間 | 90 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 14,208 KB |
| 最終ジャッジ日時 | 2024-07-19 19:03:55 |
| 合計ジャッジ時間 | 5,142 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
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)]
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[y][nx], nx, y))
for ny in [y - 1, y + 1]:
if 0 <= ny < N:
heappush(que, (d + L[ny][x], x, ny))
if minDistFromOrigin[N - 1][N - 1] < V:
print('YES')
exit()
if 0 <= X < N and 0 <= Y < N:
minDistFromOasis = [[float('inf')] * N for _ in range(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[y][nx], nx, y))
for ny in [y - 1, y + 1]:
if 0 <= ny < N:
heappush(que, (d + L[ny][x], x, ny))
life = (V - minDistFromOrigin[X][Y]) * 2
if life > minDistFromOasis[N - 1][N - 1]:
print('YES')
exit()
print('NO')