結果
| 問題 | No.34 砂漠の行商人 |
| コンテスト | |
| ユーザー |
brthyyjp
|
| 提出日時 | 2021-11-03 02:57:25 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 304 ms / 5,000 ms |
| コード長 | 792 bytes |
| コンパイル時間 | 747 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 110,464 KB |
| 最終ジャッジ日時 | 2024-10-12 11:06:44 |
| 合計ジャッジ時間 | 4,039 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, v, sx, sy, gx, gy = map(int, input().split())
sx, sy = sx-1, sy-1
gx, gy = gx-1, gy-1
L = []
for i in range(n):
l = list(map(int, input().split()))
L += l
s = sy*n+sx
g = gy*n+gx
from collections import deque
q = [(0, v, s)]
q = deque(q)
HP = [0]*(n*n)
HP[s] = v
while q:
time, hp, i = q.popleft()
y, x = divmod(i, n)
if i == g:
print(time)
exit()
for dy, dx in (-1, 0), (1, 0), (0, 1), (0, -1):
ny, nx = y+dy, x+dx
if 0 <= ny < n and 0 <= nx < n:
j = ny*n+nx
if hp-L[j] <= 0:
continue
if hp-L[j] > HP[j]:
HP[j] = hp-L[j]
q.append((time+1, hp-L[j], j))
print(-1)
brthyyjp