結果

問題 No.34 砂漠の行商人
ユーザー 👑 colognecologne
提出日時 2022-01-23 16:41:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 942 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 21,760 KB
最終ジャッジ日時 2024-05-07 05:09:24
合計ジャッジ時間 12,385 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 58 ms
10,880 KB
testcase_03 AC 30 ms
10,752 KB
testcase_04 AC 744 ms
15,232 KB
testcase_05 AC 686 ms
15,360 KB
testcase_06 AC 66 ms
11,008 KB
testcase_07 AC 1,272 ms
17,664 KB
testcase_08 AC 1,803 ms
21,760 KB
testcase_09 AC 28 ms
10,624 KB
testcase_10 AC 28 ms
10,752 KB
testcase_11 AC 28 ms
10,752 KB
testcase_12 AC 334 ms
15,232 KB
testcase_13 AC 28 ms
10,624 KB
testcase_14 AC 28 ms
10,752 KB
testcase_15 AC 27 ms
10,624 KB
testcase_16 AC 27 ms
10,624 KB
testcase_17 AC 28 ms
10,752 KB
testcase_18 AC 27 ms
10,752 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)]
    hp = [[0]*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 (r, c) == (GY-1, GX-1):
            print(d)
            return
        if vis[r][c][v]:
            continue
        vis[r][c][v] = True
        if hp[r][c] >= v:
            continue
        hp[r][c] = v
        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