結果

問題 No.34 砂漠の行商人
ユーザー 👑 rin204rin204
提出日時 2022-07-10 16:56:27
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 952 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 848,692 KB
最終ジャッジ日時 2023-09-01 23:57:01
合計ジャッジ時間 5,116 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,836 KB
testcase_01 AC 101 ms
77,448 KB
testcase_02 AC 118 ms
77,696 KB
testcase_03 AC 91 ms
71,940 KB
testcase_04 AC 148 ms
80,768 KB
testcase_05 AC 143 ms
81,356 KB
testcase_06 AC 116 ms
78,104 KB
testcase_07 AC 159 ms
83,548 KB
testcase_08 AC 188 ms
87,152 KB
testcase_09 MLE -
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 #

from collections import deque

n, v, sy, sx, gy, gx = map(int, input().split())
L = [list(map(int, input().split())) for _ in range(n)]
sx -= 1
sy -= 1
gx -= 1
gy -= 1
dist = [-1] * (n * n * v)
def f(i, j, k):
    return (i * n + j) * v + k
dist[f(sx, sy, v - 1)] = 0
queue = deque()
queue.append(f(sx, sy, v - 1))
directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
while queue:
    tmp = queue.popleft()
    x = tmp // (n * v)
    tmp -= x * n * v
    y = tmp // v
    vv = tmp - y * v
    
    for dx, dy in directions:
        nx = x + dx
        ny = y + dy
        if nx == -1 or nx == n or ny == -1 or ny == n:
            continue
        nv = vv - L[nx][ny]
        if nv < 0:
            continue
        if dist[f(nx, ny, nv)] == -1:
            if nx == gx and ny == gy:
                print(dist[f(x, y, vv)] + 1)
                exit()
            dist[f(nx, ny, nv)] = dist[f(x, y, vv)] + 1
            queue.append(f(nx, ny, nv))
print(-1)
0