結果

問題 No.34 砂漠の行商人
ユーザー brthyyjpbrthyyjp
提出日時 2021-11-03 02:54:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 820 bytes
コンパイル時間 291 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 20,896 KB
最終ジャッジ日時 2024-04-20 15:24:04
合計ジャッジ時間 10,932 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,880 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 59 ms
10,752 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 627 ms
11,392 KB
testcase_05 AC 591 ms
11,264 KB
testcase_06 AC 68 ms
10,752 KB
testcase_07 AC 1,083 ms
11,264 KB
testcase_08 AC 1,487 ms
11,520 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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
import heapq
hq = [(0, v, s)]
HP = [0]*(n*n)
HP[s] = v
heapq.heapify(hq)
visit = [False]*(n*n)
while hq:
    time, hp, i = heapq.heappop(hq)
    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]
                heapq.heappush(hq, (time+1, hp-L[j], j))
print(-1)
0