結果

問題 No.34 砂漠の行商人
ユーザー chocoruskchocorusk
提出日時 2020-09-09 10:00:52
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 833 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 852,480 KB
最終ジャッジ日時 2024-05-08 09:26:13
合計ジャッジ時間 5,595 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
53,888 KB
testcase_01 AC 55 ms
60,672 KB
testcase_02 AC 68 ms
65,664 KB
testcase_03 AC 48 ms
53,632 KB
testcase_04 AC 112 ms
78,976 KB
testcase_05 AC 108 ms
79,616 KB
testcase_06 AC 69 ms
66,048 KB
testcase_07 AC 127 ms
81,536 KB
testcase_08 AC 149 ms
85,248 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 #

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
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