結果

問題 No.34 砂漠の行商人
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-07-15 12:55:45
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 1,358 bytes
コンパイル時間 2,650 ms
コンパイル使用メモリ 86,568 KB
実行使用メモリ 825,512 KB
最終ジャッジ日時 2023-10-15 03:50:05
合計ジャッジ時間 9,693 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
72,708 KB
testcase_01 AC 117 ms
72,748 KB
testcase_02 AC 420 ms
122,928 KB
testcase_03 AC 339 ms
107,828 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
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 #

from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

N,V,sy,sx,gy,gx = map(int,input().split())
sx -= 1
sy -= 1
gx -= 1
gy -= 1
A = [list(map(int,input().split())) for _ in range(N)]
e = [[] for _ in range(N**4)]
INF = (1<<60)
def dijkstra(s,e):
    
    N = len(e)
    dist = [INF]*N
    dist[s]=0
    h = []
    heappush(h,(0,s))
    while h:
        nw,v = heappop(h)
        if dist[v]!=nw:
            continue
        for iv,ic in e[v]:
            nc = ic + nw
            if nc < dist[iv]:
                dist[iv] = nc
                heappush(h,(nc,iv))
    return dist
    
H = N
W = N
def nb(x,y):
    tmp = []
    if x+1<H:
        tmp.append((x+1,y))
    if x-1>=0:
        tmp.append((x-1,y))
    if y+1<W:
        tmp.append((x,y+1))
    if y-1>=0:
        tmp.append((x,y-1))
    return tmp

M = N**2
for i in range(H):
    for j in range(W):
        s = N*i + j
        for ix,iy in nb(i,j):
            t = N*ix + iy
            a = A[ix][iy]
            for n in range(M-1):
                ss = n*M + s
                tt = (n+1)*M + t
                e[ss].append((tt,a))
                
                
d = dijkstra(sx*N+sy,e)    
g = N*gx + gy
ans = INF
for i in range(M):
    gg = i*M + g
    if d[gg]<V:
        print(i)
        exit()
print(-1)
0