結果

問題 No.34 砂漠の行商人
ユーザー KudeKude
提出日時 2020-09-05 20:42:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 885 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 82,152 KB
実行使用メモリ 409,088 KB
最終ジャッジ日時 2024-11-29 06:07:03
合計ジャッジ時間 18,472 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
57,984 KB
testcase_01 AC 41 ms
60,624 KB
testcase_02 AC 88 ms
76,876 KB
testcase_03 AC 38 ms
52,992 KB
testcase_04 AC 417 ms
85,888 KB
testcase_05 AC 400 ms
85,760 KB
testcase_06 AC 87 ms
77,056 KB
testcase_07 AC 590 ms
91,628 KB
testcase_08 AC 804 ms
100,480 KB
testcase_09 AC 39 ms
59,392 KB
testcase_10 AC 39 ms
60,032 KB
testcase_11 AC 39 ms
60,032 KB
testcase_12 AC 440 ms
87,496 KB
testcase_13 AC 42 ms
60,032 KB
testcase_14 AC 40 ms
59,904 KB
testcase_15 AC 39 ms
58,880 KB
testcase_16 AC 40 ms
58,880 KB
testcase_17 AC 41 ms
59,648 KB
testcase_18 AC 36 ms
52,608 KB
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 100 ms
80,768 KB
testcase_22 AC 39 ms
59,648 KB
testcase_23 AC 38 ms
59,008 KB
testcase_24 AC 40 ms
59,904 KB
testcase_25 AC 1,548 ms
409,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop
n, v, sy, sx, gy, gx = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
sx -= 1
sy -= 1
gx -= 1
gy -= 1
shortest_dist = abs(sx - gx) + abs(sy - gy)
if v > shortest_dist * 9:
    print(shortest_dist)
    exit(0)
INF = 10 ** 4
dist = [[[INF for _ in range(v + 1)] for _ in range(n)] for _ in range(n)]
dist[sx][sy][v] = 0
q = [(0, sx, sy, v)]
while q:
    d, x, y, vit = heappop(q)
    if d > dist[x][y][vit]:
        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
        nvit = vit - l[nx][ny]
        nd = d + 1
        if nvit > 0 and nd< dist[nx][ny][nvit]:
            dist[nx][ny][nvit] = nd
            heappush(q, (nd, nx, ny, nvit))
ans = min(dist[gx][gy])
if ans == INF:
    ans = -1
print(ans)
0