結果

問題 No.34 砂漠の行商人
ユーザー KudeKude
提出日時 2020-09-05 20:27:52
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 746 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 82,408 KB
実行使用メモリ 340,996 KB
最終ジャッジ日時 2024-05-06 20:06:46
合計ジャッジ時間 31,180 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
73,216 KB
testcase_01 AC 86 ms
74,112 KB
testcase_02 AC 275 ms
85,832 KB
testcase_03 AC 233 ms
83,552 KB
testcase_04 AC 918 ms
135,552 KB
testcase_05 AC 1,163 ms
154,100 KB
testcase_06 AC 848 ms
112,384 KB
testcase_07 AC 1,723 ms
196,712 KB
testcase_08 AC 1,742 ms
217,600 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 WA -
testcase_12 AC 1,130 ms
146,944 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 753 ms
134,112 KB
testcase_16 AC 925 ms
137,648 KB
testcase_17 AC 1,860 ms
217,812 KB
testcase_18 AC 298 ms
88,320 KB
testcase_19 AC 2,065 ms
267,904 KB
testcase_20 WA -
testcase_21 AC 1,183 ms
249,344 KB
testcase_22 AC 2,011 ms
264,192 KB
testcase_23 AC 932 ms
154,752 KB
testcase_24 WA -
testcase_25 AC 957 ms
176,640 KB
権限があれば一括ダウンロードができます

ソースコード

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 < 200 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