結果

問題 No.34 砂漠の行商人
ユーザー kept1994kept1994
提出日時 2022-05-07 17:39:48
言語 PyPy3
(7.3.13)
結果
TLE  
実行時間 -
コード長 1,264 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 448,620 KB
最終ジャッジ日時 2023-09-21 04:23:59
合計ジャッジ時間 17,389 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,588 KB
testcase_01 AC 99 ms
76,540 KB
testcase_02 AC 114 ms
77,504 KB
testcase_03 AC 98 ms
73,176 KB
testcase_04 AC 201 ms
116,280 KB
testcase_05 AC 211 ms
128,076 KB
testcase_06 AC 135 ms
99,044 KB
testcase_07 AC 259 ms
153,912 KB
testcase_08 AC 333 ms
183,196 KB
testcase_09 AC 2,314 ms
311,888 KB
testcase_10 AC 443 ms
227,808 KB
testcase_11 TLE -
testcase_12 AC 195 ms
116,756 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
import sys
from collections import deque
MOD = 998244353

input = sys.stdin.readline

powerMax = 99 * 2 * 9
INF = 10 ** 16

def main():
    N, V, Sx, Sy, Gx, Gy = map(int, input().split())
    power_init = min(V, powerMax)
    G = [list(map(int, input().split())) for _ in range(N)]
    startY = Sy - 1
    startX = Sx - 1
    goalY = Gy - 1
    goalX = Gx - 1
    q = deque()
    dist = [[[INF] * (powerMax + 1) for _ in range(N)] for _ in range(N)]
    q.append((0, startY, startX, power_init))
    dist[startY][startX][power_init] = 0
    while q:
        min_cost, nowY, nowX, now_power = q.popleft()
        if nowY == goalY and nowX == goalX:
            print(min_cost)
            return
        for dx, dy in [(0, 1), (1, 0), (-1, 0), (0, -1)]:
            nexty = nowY + dy
            nextx = nowX + dx
            if nexty < 0 or nextx < 0 or nexty >= N or nextx >= N:
                continue
            next_power = now_power - G[nexty][nextx]
            if next_power <= 0 or dist[nexty][nextx][next_power] != INF:
                continue
            q.append((min_cost + 1, nexty, nextx, next_power))
            dist[nexty][nextx][next_power] = min_cost + 1
    print(-1)
    return

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