結果

問題 No.34 砂漠の行商人
ユーザー tktk_snsntktk_snsn
提出日時 2021-05-17 19:51:41
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 919 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 850,824 KB
最終ジャッジ日時 2024-04-16 08:09:16
合計ジャッジ時間 6,127 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
54,272 KB
testcase_01 AC 58 ms
62,464 KB
testcase_02 AC 76 ms
69,248 KB
testcase_03 AC 48 ms
54,912 KB
testcase_04 AC 127 ms
80,896 KB
testcase_05 AC 128 ms
81,920 KB
testcase_06 AC 84 ms
71,168 KB
testcase_07 AC 156 ms
84,608 KB
testcase_08 AC 166 ms
88,832 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
import heapq
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[sx*N+sy][V] = 0
que = deque([(sx*N+sy, V)])
ans = -1
while que:
    xy, v = que.popleft()
    x, y = divmod(xy, N)
    d = dist[xy][v]
    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]
            nxy = nx * N + ny
            if dist[nxy][nv] == -1:
                dist[nxy][nv] = d + 1
                que.append((nxy, nv))

print(ans)
0