結果

問題 No.34 砂漠の行商人
ユーザー KudeKude
提出日時 2020-09-05 20:26:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 266 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 229,344 KB
最終ジャッジ日時 2024-05-06 20:06:09
合計ジャッジ時間 24,616 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
72,960 KB
testcase_01 AC 71 ms
73,728 KB
testcase_02 AC 227 ms
79,456 KB
testcase_03 AC 194 ms
78,208 KB
testcase_04 AC 749 ms
101,040 KB
testcase_05 AC 930 ms
107,136 KB
testcase_06 AC 700 ms
84,864 KB
testcase_07 AC 1,412 ms
125,696 KB
testcase_08 AC 1,409 ms
122,496 KB
testcase_09 WA -
testcase_10 AC 4,396 ms
229,344 KB
testcase_11 WA -
testcase_12 AC 877 ms
110,592 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 587 ms
93,184 KB
testcase_16 AC 696 ms
97,024 KB
testcase_17 AC 1,405 ms
135,924 KB
testcase_18 AC 239 ms
81,024 KB
testcase_19 AC 1,602 ms
145,792 KB
testcase_20 WA -
testcase_21 AC 897 ms
111,872 KB
testcase_22 AC 1,655 ms
146,048 KB
testcase_23 AC 729 ms
100,096 KB
testcase_24 WA -
testcase_25 AC 753 ms
102,528 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] * 200 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