結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-11-13 08:48:39 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 198 ms / 5,000 ms |
| コード長 | 959 bytes |
| コンパイル時間 | 233 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 13,696 KB |
| 最終ジャッジ日時 | 2024-09-14 17:26:28 |
| 合計ジャッジ時間 | 2,919 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 |
ソースコード
import sys
from heapq import heappush, heappop
def dijkstra(y, x):
dp = [[float('inf')] * N for _ in range(N)]
dp[y][x] = 0
hq = [(0, y, x)]
while(hq):
h, sy, sx = heappop(hq)
if dp[sy][sx] < h:
continue
for dy, dx in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
ny = sy + dy
nx = sx + dx
if 0 <= ny < N and 0 <= nx < N and dp[ny][nx] > h + sand_area[ny][nx]:
dp[ny][nx] = h + sand_area[ny][nx]
heappush(hq, (h + sand_area[ny][nx], ny, nx))
return dp
N, V, Ox, Oy = map(int, input().split())
Ox -= 1
Oy -= 1
sand_area = [list(map(int, input().split())) for _ in range(N)]
dp1 = dijkstra(0, 0)
if Ox == Oy == -1:
if dp1[N - 1][N - 1] < V:
print("YES")
else:
print("NO")
sys.exit(0)
dp2 = dijkstra(Oy, Ox)
if dp1[N - 1][N - 1] < V or (V - dp1[Oy][Ox]) * 2 > dp2[N - 1][N - 1]:
print("YES")
else:
print("NO")