結果

問題 No.34 砂漠の行商人
ユーザー maspymaspy
提出日時 2020-03-21 02:37:39
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 971 bytes
コンパイル時間 691 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 841,332 KB
最終ジャッジ日時 2023-08-22 09:15:29
合計ジャッジ時間 5,522 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
72,628 KB
testcase_01 AC 103 ms
78,652 KB
testcase_02 AC 123 ms
112,044 KB
testcase_03 AC 103 ms
99,904 KB
testcase_04 AC 199 ms
273,532 KB
testcase_05 AC 220 ms
341,064 KB
testcase_06 AC 154 ms
229,316 KB
testcase_07 AC 269 ms
471,732 KB
testcase_08 MLE -
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 #

#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from collections import deque

N, V, Sy, Sx, Gy, Gx = map(int, readline().split())
L = tuple(map(int, read().split()))
Sx -= 1
Sy -= 1
Gx -= 1
Gy -= 1
S = Sx * N + Sy
G = Gx * N + Gy

INF = 1000
M = N * N
dist = [INF] * (M * 10001)
start = M * V + S
dist[start] = 0
q = deque([start])

answer = INF
while q:
    x = q.popleft()
    d = dist[x]
    V, xy = divmod(x, M)
    x, y = divmod(xy, N)
    d += 1
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        x1 = x + dx
        y1 = y + dy
        if not ((0 <= x1 < N) and (0 <= y1 < N)):
            continue
        xy1 = x1 * N + y1
        V1 = V - L[xy1]
        if V1 <= 0:
            continue
        if xy1 == G:
            print(d)
            exit()
        v = M * V1 + xy1
        if dist[v] == INF:
            dist[v] = d
            q.append(v)

print(-1)
0