結果

問題 No.34 砂漠の行商人
ユーザー chocoruskchocorusk
提出日時 2020-09-09 10:29:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 312 ms / 5,000 ms
コード長 812 bytes
コンパイル時間 2,018 ms
コンパイル使用メモリ 86,516 KB
実行使用メモリ 93,120 KB
最終ジャッジ日時 2023-08-21 04:28:28
合計ジャッジ時間 5,674 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,552 KB
testcase_01 AC 95 ms
71,212 KB
testcase_02 AC 108 ms
77,324 KB
testcase_03 AC 96 ms
71,540 KB
testcase_04 AC 119 ms
77,472 KB
testcase_05 AC 122 ms
77,424 KB
testcase_06 AC 113 ms
77,556 KB
testcase_07 AC 134 ms
77,512 KB
testcase_08 AC 138 ms
77,692 KB
testcase_09 AC 174 ms
77,836 KB
testcase_10 AC 116 ms
78,252 KB
testcase_11 AC 126 ms
77,948 KB
testcase_12 AC 114 ms
77,344 KB
testcase_13 AC 312 ms
93,120 KB
testcase_14 AC 251 ms
85,460 KB
testcase_15 AC 113 ms
77,464 KB
testcase_16 AC 122 ms
77,384 KB
testcase_17 AC 103 ms
76,584 KB
testcase_18 AC 113 ms
76,900 KB
testcase_19 AC 163 ms
78,364 KB
testcase_20 AC 194 ms
82,116 KB
testcase_21 AC 110 ms
77,944 KB
testcase_22 AC 110 ms
77,728 KB
testcase_23 AC 109 ms
77,288 KB
testcase_24 AC 213 ms
82,028 KB
testcase_25 AC 117 ms
77,488 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