結果

問題 No.34 砂漠の行商人
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-17 19:56:38
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 962 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,476 KB
実行使用メモリ 848,380 KB
最終ジャッジ日時 2024-04-16 08:11:23
合計ジャッジ時間 2,903 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
54,248 KB
testcase_01 AC 53 ms
63,252 KB
testcase_02 AC 68 ms
69,104 KB
testcase_03 AC 45 ms
56,368 KB
testcase_04 AC 118 ms
80,892 KB
testcase_05 AC 117 ms
80,940 KB
testcase_06 AC 70 ms
70,836 KB
testcase_07 AC 138 ms
83,248 KB
testcase_08 AC 163 ms
87,768 KB
testcase_09 MLE -
testcase_10 -- -
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
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
DX = DX[:4]
DY = DY[:4]


N, V, sy, sx, gy, gx = map(int, input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
L = tuple(tuple(map(int, input().split())) for _ in range(N))
Nsq = N*N

dist = [[-1]*(V+1) for _ in range(N*N)]
dist = [-1] * ((V+1)*Nsq)
dist[V*Nsq+sx*N+sy] = 0
que = deque([V*Nsq+sx*N+sy])
ans = -1
while que:
    vxy = que.popleft()
    v, xy = divmod(vxy, Nsq)
    x, y = divmod(xy, N)
    d = dist[vxy]
    if (x, y) == (gx, gy):
        ans = d
        break
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        if 0 <= nx < N and 0 <= ny < N and v - L[nx][ny] > 0:
            nv = v - L[nx][ny]
            nvxy = nv * Nsq + nx * N + ny
            if dist[nvxy] == -1:
                dist[nvxy] = d + 1
                que.append(nvxy)

print(ans)
0