結果

問題 No.34 砂漠の行商人
ユーザー 👑 colognecologne
提出日時 2022-01-23 16:36:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 839 bytes
コンパイル時間 107 ms
コンパイル使用メモリ 10,944 KB
実行使用メモリ 72,436 KB
最終ジャッジ日時 2023-08-19 21:56:46
合計ジャッジ時間 13,961 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,024 KB
testcase_01 AC 17 ms
8,092 KB
testcase_02 AC 48 ms
8,456 KB
testcase_03 AC 17 ms
8,208 KB
testcase_04 AC 884 ms
13,444 KB
testcase_05 AC 892 ms
13,964 KB
testcase_06 AC 52 ms
8,416 KB
testcase_07 AC 1,501 ms
16,312 KB
testcase_08 AC 2,146 ms
20,568 KB
testcase_09 AC 18 ms
8,004 KB
testcase_10 AC 19 ms
8,032 KB
testcase_11 AC 19 ms
8,016 KB
testcase_12 AC 588 ms
14,204 KB
testcase_13 AC 18 ms
8,000 KB
testcase_14 AC 19 ms
8,088 KB
testcase_15 AC 18 ms
8,208 KB
testcase_16 AC 18 ms
8,280 KB
testcase_17 AC 17 ms
8,152 KB
testcase_18 AC 16 ms
8,244 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import heapq

input = sys.stdin.readline


def main():
    N, V, SX, SY, GX, GY = map(int, input().split())
    L = [list(map(int, input().split())) for i in range(N)]

    if V > (abs(SX-GX) + abs(SY-GY)) * 9:
        print(abs(SX-GX) + abs(SY-GY))
        return

    vis = [[[False]*(V+1) for i in range(N)] for i in range(N)]

    Q = [(0, SY-1, SX-1, V)]
    while len(Q) > 0:
        d, r, c, v = heapq.heappop(Q)
        if vis[r][c][v]:
            continue
        if (r, c) == (GY-1, GX-1):
            print(d)
            return
        vis[r][c][v] = True
        for dx, dy in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            x, y = r+dx, c+dy
            if 0 <= x < N and 0 <= y < N and v > L[x][y]:
                heapq.heappush(Q, (d+1, x, y, v-L[x][y]))

    print(-1)


if __name__ == '__main__':
    main()
0