結果

問題 No.34 砂漠の行商人
ユーザー KudeKude
提出日時 2020-09-05 20:27:52
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 746 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 342,728 KB
最終ジャッジ日時 2023-08-19 13:03:20
合計ジャッジ時間 30,703 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
77,536 KB
testcase_01 AC 116 ms
77,696 KB
testcase_02 AC 291 ms
87,260 KB
testcase_03 AC 247 ms
85,408 KB
testcase_04 AC 896 ms
135,768 KB
testcase_05 AC 1,112 ms
155,856 KB
testcase_06 AC 845 ms
113,836 KB
testcase_07 AC 1,681 ms
195,784 KB
testcase_08 AC 1,799 ms
222,668 KB
testcase_09 WA -
testcase_10 TLE -
testcase_11 WA -
testcase_12 AC 1,018 ms
147,548 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 717 ms
136,076 KB
testcase_16 AC 845 ms
137,752 KB
testcase_17 AC 1,633 ms
216,952 KB
testcase_18 AC 294 ms
90,496 KB
testcase_19 AC 1,925 ms
268,168 KB
testcase_20 WA -
testcase_21 AC 1,145 ms
252,352 KB
testcase_22 AC 1,941 ms
264,912 KB
testcase_23 AC 885 ms
155,760 KB
testcase_24 WA -
testcase_25 AC 916 ms
178,232 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