結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,752 KB
testcase_01 AC 32 ms
10,752 KB
testcase_02 AC 69 ms
11,136 KB
testcase_03 AC 33 ms
10,624 KB
testcase_04 AC 1,058 ms
15,872 KB
testcase_05 AC 1,072 ms
16,512 KB
testcase_06 AC 73 ms
11,136 KB
testcase_07 AC 1,793 ms
18,560 KB
testcase_08 AC 2,585 ms
22,912 KB
testcase_09 AC 32 ms
10,752 KB
testcase_10 AC 34 ms
10,624 KB
testcase_11 AC 33 ms
10,624 KB
testcase_12 AC 718 ms
16,640 KB
testcase_13 AC 34 ms
10,752 KB
testcase_14 AC 34 ms
10,752 KB
testcase_15 AC 32 ms
10,752 KB
testcase_16 AC 32 ms
10,624 KB
testcase_17 AC 33 ms
10,752 KB
testcase_18 AC 31 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)]

    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