結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,728 KB
testcase_01 AC 103 ms
77,212 KB
testcase_02 AC 118 ms
77,560 KB
testcase_03 AC 92 ms
71,732 KB
testcase_04 AC 188 ms
100,664 KB
testcase_05 AC 191 ms
100,508 KB
testcase_06 AC 119 ms
77,972 KB
testcase_07 AC 237 ms
107,416 KB
testcase_08 AC 299 ms
134,692 KB
testcase_09 AC 3,158 ms
407,328 KB
testcase_10 AC 333 ms
131,628 KB
testcase_11 MLE -
testcase_12 AC 694 ms
94,104 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 #

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 = {}
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 f(nx, ny, nv) not in dist:
            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