結果

問題 No.34 砂漠の行商人
ユーザー chocoruskchocorusk
提出日時 2020-09-09 10:29:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 272 ms / 5,000 ms
コード長 812 bytes
コンパイル時間 820 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 91,136 KB
最終ジャッジ日時 2024-05-08 10:00:34
合計ジャッジ時間 4,003 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
53,760 KB
testcase_01 AC 45 ms
53,888 KB
testcase_02 AC 55 ms
62,976 KB
testcase_03 AC 47 ms
53,888 KB
testcase_04 AC 71 ms
69,760 KB
testcase_05 AC 73 ms
71,040 KB
testcase_06 AC 60 ms
65,024 KB
testcase_07 AC 88 ms
76,416 KB
testcase_08 AC 95 ms
76,800 KB
testcase_09 AC 136 ms
80,060 KB
testcase_10 AC 69 ms
68,992 KB
testcase_11 AC 82 ms
76,172 KB
testcase_12 AC 65 ms
65,920 KB
testcase_13 AC 272 ms
91,136 KB
testcase_14 AC 211 ms
87,032 KB
testcase_15 AC 58 ms
64,384 KB
testcase_16 AC 73 ms
70,656 KB
testcase_17 AC 50 ms
60,800 KB
testcase_18 AC 60 ms
64,512 KB
testcase_19 AC 115 ms
76,672 KB
testcase_20 AC 147 ms
80,272 KB
testcase_21 AC 58 ms
65,536 KB
testcase_22 AC 59 ms
65,792 KB
testcase_23 AC 59 ms
64,512 KB
testcase_24 AC 171 ms
83,072 KB
testcase_25 AC 68 ms
69,108 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)
hmn=[v]*(n*n)
hmn[sy*n+sx]=0
from collections import deque
que=deque()
que.append((sy*n+sx, 0))
while que:
    hxy, d=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
        hmn[xy1]=h1
        if x1==gy and y1==gx:
            print(d+1)
            exit()
        que.append((hxy1, d+1))
print(-1)
0