結果

問題 No.34 砂漠の行商人
ユーザー KudeKude
提出日時 2020-09-05 20:26:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 86,696 KB
実行使用メモリ 229,876 KB
最終ジャッジ日時 2023-08-19 13:02:42
合計ジャッジ時間 25,775 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 98 ms
77,312 KB
testcase_01 AC 103 ms
77,316 KB
testcase_02 AC 256 ms
81,116 KB
testcase_03 AC 213 ms
79,548 KB
testcase_04 AC 767 ms
101,476 KB
testcase_05 AC 951 ms
107,152 KB
testcase_06 AC 706 ms
86,292 KB
testcase_07 AC 1,424 ms
124,968 KB
testcase_08 AC 1,390 ms
122,844 KB
testcase_09 WA -
testcase_10 AC 4,277 ms
229,876 KB
testcase_11 WA -
testcase_12 AC 946 ms
113,212 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 607 ms
93,660 KB
testcase_16 AC 714 ms
99,548 KB
testcase_17 AC 1,380 ms
138,124 KB
testcase_18 AC 256 ms
81,924 KB
testcase_19 AC 1,582 ms
149,220 KB
testcase_20 WA -
testcase_21 AC 871 ms
114,088 KB
testcase_22 AC 1,594 ms
149,848 KB
testcase_23 AC 723 ms
100,072 KB
testcase_24 WA -
testcase_25 AC 736 ms
102,804 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