結果

問題 No.34 砂漠の行商人
ユーザー maspymaspy
提出日時 2020-03-21 02:43:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 291 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 91,136 KB
最終ジャッジ日時 2024-05-09 15:01:57
合計ジャッジ時間 3,819 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
53,760 KB
testcase_01 AC 47 ms
53,888 KB
testcase_02 AC 62 ms
63,744 KB
testcase_03 AC 48 ms
53,888 KB
testcase_04 AC 80 ms
70,144 KB
testcase_05 AC 80 ms
71,808 KB
testcase_06 AC 68 ms
65,536 KB
testcase_07 AC 106 ms
76,544 KB
testcase_08 AC 105 ms
76,544 KB
testcase_09 AC 142 ms
80,384 KB
testcase_10 AC 72 ms
69,504 KB
testcase_11 AC 89 ms
76,928 KB
testcase_12 AC 67 ms
65,920 KB
testcase_13 AC 291 ms
91,136 KB
testcase_14 AC 229 ms
87,168 KB
testcase_15 AC 62 ms
64,256 KB
testcase_16 AC 77 ms
69,760 KB
testcase_17 AC 54 ms
61,312 KB
testcase_18 AC 63 ms
64,384 KB
testcase_19 AC 127 ms
76,928 KB
testcase_20 AC 161 ms
80,256 KB
testcase_21 AC 65 ms
66,304 KB
testcase_22 AC 63 ms
65,792 KB
testcase_23 AC 64 ms
64,384 KB
testcase_24 AC 187 ms
83,840 KB
testcase_25 AC 73 ms
68,864 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