結果

問題 No.34 砂漠の行商人
ユーザー maspymaspy
提出日時 2020-03-21 02:44:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 950 bytes
コンパイル時間 199 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 24,064 KB
最終ジャッジ日時 2024-12-16 05:15:48
合計ジャッジ時間 31,665 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
24,064 KB
testcase_01 AC 31 ms
11,008 KB
testcase_02 AC 40 ms
10,880 KB
testcase_03 AC 31 ms
10,880 KB
testcase_04 AC 364 ms
10,880 KB
testcase_05 AC 404 ms
11,008 KB
testcase_06 AC 69 ms
10,880 KB
testcase_07 AC 889 ms
11,136 KB
testcase_08 AC 1,086 ms
11,264 KB
testcase_09 AC 2,967 ms
11,648 KB
testcase_10 AC 235 ms
11,008 KB
testcase_11 AC 689 ms
11,520 KB
testcase_12 AC 102 ms
10,880 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 AC 43 ms
10,880 KB
testcase_16 AC 346 ms
11,008 KB
testcase_17 AC 33 ms
10,752 KB
testcase_18 AC 54 ms
10,880 KB
testcase_19 AC 2,278 ms
12,288 KB
testcase_20 AC 3,718 ms
12,544 KB
testcase_21 AC 40 ms
10,880 KB
testcase_22 AC 61 ms
10,880 KB
testcase_23 AC 37 ms
10,880 KB
testcase_24 AC 4,650 ms
12,416 KB
testcase_25 AC 240 ms
23,552 KB
権限があれば一括ダウンロードができます

ソースコード

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

best_v = [0] * M
start = M * V + S
q = deque([(start, 0)])

answer = INF
while q:
    x, d = q.popleft()
    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 best_v[xy1] < V1:
            best_v[xy1] = V1
            q.append((v, d))

print(-1)
0