結果

問題 No.34 砂漠の行商人
ユーザー chocoruskchocorusk
提出日時 2020-09-09 10:15:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,217 ms / 5,000 ms
コード長 901 bytes
コンパイル時間 1,706 ms
コンパイル使用メモリ 81,664 KB
実行使用メモリ 251,736 KB
最終ジャッジ日時 2024-05-08 09:36:11
合計ジャッジ時間 7,140 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
53,760 KB
testcase_01 AC 48 ms
54,016 KB
testcase_02 AC 65 ms
63,872 KB
testcase_03 AC 48 ms
53,760 KB
testcase_04 AC 90 ms
81,536 KB
testcase_05 AC 96 ms
84,608 KB
testcase_06 AC 67 ms
66,304 KB
testcase_07 AC 155 ms
95,008 KB
testcase_08 AC 165 ms
102,024 KB
testcase_09 AC 376 ms
139,488 KB
testcase_10 AC 83 ms
76,416 KB
testcase_11 AC 125 ms
92,288 KB
testcase_12 AC 71 ms
69,248 KB
testcase_13 AC 1,217 ms
251,736 KB
testcase_14 AC 777 ms
193,096 KB
testcase_15 AC 66 ms
65,432 KB
testcase_16 AC 96 ms
81,920 KB
testcase_17 AC 57 ms
60,928 KB
testcase_18 AC 69 ms
64,896 KB
testcase_19 AC 325 ms
140,960 KB
testcase_20 AC 512 ms
163,040 KB
testcase_21 AC 74 ms
66,304 KB
testcase_22 AC 67 ms
66,816 KB
testcase_23 AC 61 ms
65,024 KB
testcase_24 AC 611 ms
163,020 KB
testcase_25 AC 89 ms
77,696 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
d={}
d[sy*n+sx]=0
hmn=[v]*(n*n)
hmn[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>=hmn[xy1]:
            continue
        hxy1=h1*n*n+xy1
        if (hxy1 not in d) or d[hxy1]>d[hxy]+1:
            hmn[xy1]=h1
            d[hxy1]=d[hxy]+1
            if x1==gy and y1==gx:
                print(d[hxy1])
                exit()
            que.append(hxy1)
print(-1)
0