結果

問題 No.34 砂漠の行商人
ユーザー vwxyzvwxyz
提出日時 2023-12-19 06:23:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 755 bytes
コンパイル時間 124 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 37,652 KB
最終ジャッジ日時 2023-12-19 06:23:46
合計ジャッジ時間 7,908 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,984 KB
testcase_01 AC 32 ms
9,984 KB
testcase_02 AC 628 ms
11,776 KB
testcase_03 AC 454 ms
11,392 KB
testcase_04 TLE -
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 #

import sys
readline=sys.stdin.readline
from collections import deque

N,V,Sy,Sx,Gy,Gx=map(int,readline().split())
Sx-=1;Sy-=1;Gx-=1;Gy-=1
L=[list(map(int,readline().split())) for x in range(N)]
queue=deque([(0,0,Sx,Sy)])
inf=1<<60
dist=[[inf]*N*N for v in range(18*N)]
dist[0][Sx*N+Sy]=0
while queue:
    d,v,x,y=queue.popleft()
    if dist[v][x*N+y]<d:
        continue
    for dx,dy in ((0,1),(1,0),(0,-1),(-1,0)):
        xx=x+dx
        yy=y+dy
        if 0<=xx<N and 0<=yy<N:
            vv=v+L[xx][yy]
            if vv<18*N and dist[vv][xx*N+yy]>d+1:
                dist[vv][xx*N+yy]=d+1
                queue.append((d+1,vv,xx,yy))
ans=inf
for v in range(18*N):
    if v<V:
        ans=min(ans,dist[v][Gx*N+Gy])
if ans==inf:
    ans=-1
print(ans)
0