結果

問題 No.34 砂漠の行商人
ユーザー 👑 colognecologne
提出日時 2022-01-23 16:33:56
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 839 bytes
コンパイル時間 1,674 ms
コンパイル使用メモリ 86,748 KB
実行使用メモリ 247,228 KB
最終ジャッジ日時 2023-08-19 21:53:09
合計ジャッジ時間 22,639 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,532 KB
testcase_01 AC 96 ms
76,416 KB
testcase_02 AC 213 ms
79,700 KB
testcase_03 AC 78 ms
71,264 KB
testcase_04 AC 1,853 ms
145,732 KB
testcase_05 AC 1,758 ms
140,960 KB
testcase_06 AC 181 ms
78,180 KB
testcase_07 AC 3,164 ms
187,884 KB
testcase_08 AC 4,166 ms
247,228 KB
testcase_09 AC 81 ms
75,656 KB
testcase_10 AC 77 ms
75,632 KB
testcase_11 AC 78 ms
75,736 KB
testcase_12 AC 1,215 ms
128,368 KB
testcase_13 AC 77 ms
75,676 KB
testcase_14 AC 82 ms
75,708 KB
testcase_15 AC 79 ms
75,672 KB
testcase_16 AC 77 ms
75,724 KB
testcase_17 AC 79 ms
75,704 KB
testcase_18 AC 75 ms
71,196 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