結果

問題 No.34 砂漠の行商人
ユーザー KudeKude
提出日時 2020-09-05 20:31:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 747 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 86,932 KB
実行使用メモリ 108,020 KB
最終ジャッジ日時 2023-08-19 13:03:45
合計ジャッジ時間 10,770 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
77,984 KB
testcase_01 AC 155 ms
77,824 KB
testcase_02 AC 1,933 ms
108,020 KB
testcase_03 AC 1,518 ms
99,184 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
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 #

from heapq import heappush, heappop
n, v, sy, sx, gy, gx = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
l = [list(map(int, input().split())) for _ in range(n)]
INF = 10 ** 18
dist = [[[INF] * 2000 for _ in range(n)] for _ in range(n)]
dist[sx][sy][0] = 0
q = [(0, sx, sy, 0)]
while q:
    d, x, y, c = heappop(q)
    if d > dist[x][y][c]:
        continue
    for dx, dy in (1, 0), (0, 1), (-1, 0), (0, -1):
        nx, ny = x + dx, y + dy
        if not (0 <= nx < n and 0 <= ny < n):
            continue
        nc = c + l[nx][ny]
        if nc < 2000 and d + 1 < dist[nx][ny][nc]:
            dist[nx][ny][nc] = d + 1
            heappush(q, (d + 1, nx, ny, nc))
ans = min(dist[gx][gy][:v])
if ans == INF:
    ans = -1
print(ans)
0