結果

問題 No.34 砂漠の行商人
ユーザー 👑 colognecologne
提出日時 2022-01-23 16:57:59
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,021 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 278,316 KB
最終ジャッジ日時 2024-05-07 05:23:12
合計ジャッジ時間 11,813 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,188 KB
testcase_01 AC 48 ms
54,616 KB
testcase_02 AC 111 ms
76,736 KB
testcase_03 AC 40 ms
54,064 KB
testcase_04 AC 664 ms
91,844 KB
testcase_05 AC 617 ms
89,640 KB
testcase_06 AC 118 ms
76,748 KB
testcase_07 AC 991 ms
98,848 KB
testcase_08 AC 1,422 ms
118,700 KB
testcase_09 AC 44 ms
60,732 KB
testcase_10 AC 43 ms
61,388 KB
testcase_11 AC 43 ms
61,416 KB
testcase_12 AC 334 ms
86,544 KB
testcase_13 AC 45 ms
60,344 KB
testcase_14 AC 45 ms
61,008 KB
testcase_15 AC 43 ms
58,768 KB
testcase_16 AC 47 ms
60,280 KB
testcase_17 AC 43 ms
59,480 KB
testcase_18 AC 41 ms
52,948 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]:
                if not vis[x][y][v-L[x][y]] and not hp[x][y] >= v-L[x][y]:
                    heapq.heappush(Q, (d+1, x, y, v-L[x][y]))

    print(-1)


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