結果

問題 No.34 砂漠の行商人
ユーザー chocoruskchocorusk
提出日時 2020-09-09 10:19:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,779 ms / 5,000 ms
コード長 848 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 328,880 KB
最終ジャッジ日時 2023-08-21 04:09:35
合計ジャッジ時間 15,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 91 ms
71,596 KB
testcase_01 AC 100 ms
76,772 KB
testcase_02 AC 111 ms
77,208 KB
testcase_03 AC 95 ms
71,716 KB
testcase_04 AC 138 ms
80,428 KB
testcase_05 AC 136 ms
80,980 KB
testcase_06 AC 112 ms
77,908 KB
testcase_07 AC 152 ms
83,112 KB
testcase_08 AC 170 ms
86,792 KB
testcase_09 AC 958 ms
200,572 KB
testcase_10 AC 202 ms
219,236 KB
testcase_11 AC 1,544 ms
280,968 KB
testcase_12 AC 124 ms
80,492 KB
testcase_13 AC 2,779 ms
328,880 KB
testcase_14 AC 2,281 ms
278,872 KB
testcase_15 AC 131 ms
118,732 KB
testcase_16 AC 228 ms
116,652 KB
testcase_17 AC 125 ms
131,420 KB
testcase_18 AC 124 ms
85,376 KB
testcase_19 AC 682 ms
146,172 KB
testcase_20 AC 1,172 ms
207,520 KB
testcase_21 AC 112 ms
81,684 KB
testcase_22 AC 139 ms
147,192 KB
testcase_23 AC 128 ms
133,428 KB
testcase_24 AC 1,476 ms
280,992 KB
testcase_25 AC 176 ms
89,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read=sys.stdin.buffer.read
readline=sys.stdin.buffer.readline
readlines=sys.stdin.buffer.readlines

n, v, sx, sy, gx, gy=map(int, readline().split())
l=list(map(int, read().split()))
sx-=1
sy-=1
gx-=1
gy-=1
INF=10**5
v=min(v, 1800)
d=[INF]*(n*n*v)
d[sy*n+sx]=0
from collections import deque
que=deque()
que.append(sy*n+sx)
while que:
    hxy=que.popleft()
    h, xy=divmod(hxy, n*n)
    x, y=divmod(xy, n)
    for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
        x1, y1=x+dx, y+dy
        if x1<0 or x1>=n or y1<0 or y1>=n:
            continue
        xy1=x1*n+y1
        h1=l[xy1]+h
        if h1>=v:
            continue
        hxy1=h1*n*n+xy1
        if d[hxy1]>d[hxy]+1:
            d[hxy1]=d[hxy]+1
            if x1==gy and y1==gx:
                print(d[hxy1])
                exit()
            que.append(hxy1)
print(-1)
0