結果
| 問題 |
No.20 砂漠のオアシス
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-01-19 01:06:46 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,017 bytes |
| コンパイル時間 | 426 ms |
| コンパイル使用メモリ | 81,948 KB |
| 実行使用メモリ | 81,268 KB |
| 最終ジャッジ日時 | 2024-06-12 00:35:14 |
| 合計ジャッジ時間 | 3,938 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 5 |
ソースコード
import heapq
INF = 1 << 60
n, v, ox, oy = map(int, input().split())
ox -= 1
oy -= 1
l = [list(map(int, input().split())) for _ in range(n)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
def cost(sx, sy, gx, gy):
dist = [[INF for _ in range(n)] for _ in range(n)]
dist[sx][sy] = 0
hp = [(0, sx, sy)]
while len(hp) > 0:
cd, cx, cy = heapq.heappop(hp)
if cd > dist[cx][cy]:
continue
for i in range(4):
nx = cx + dx[i]
ny = cy + dy[i]
if nx < 0 or nx >= n or ny < 0 or ny >= n:
continue
if dist[nx][ny] > dist[cx][cy] + l[nx][ny]:
dist[nx][ny] = dist[cx][cy] + l[nx][ny]
heapq.heappush(hp, (dist[nx][ny], nx, ny))
return dist[gx][gy]
if ox == -1 and oy == -1:
rest = v - cost(0, 0, n - 1, n - 1)
if rest <= 0:
print("NO")
else:
print("YES")
else:
rest = v - cost(0, 0, ox, oy)
if rest <= 0:
print("NO")
else:
rest = 2 * rest - cost(ox, oy, n - 1, n - 1)
if rest <= 0:
print("NO")
else:
print("YES")