結果
| 問題 | No.34 砂漠の行商人 | 
| コンテスト | |
| ユーザー |  chocorusk | 
| 提出日時 | 2020-09-09 10:29:20 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 259 ms / 5,000 ms | 
| コード長 | 812 bytes | 
| コンパイル時間 | 311 ms | 
| コンパイル使用メモリ | 82,432 KB | 
| 実行使用メモリ | 91,328 KB | 
| 最終ジャッジ日時 | 2024-12-14 13:07:31 | 
| 合計ジャッジ時間 | 3,634 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 26 | 
ソースコード
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)
            
            
            
        