結果

問題 No.34 砂漠の行商人
ユーザー vwxyzvwxyz
提出日時 2023-12-19 06:22:22
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 768 bytes
コンパイル時間 156 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 597,732 KB
最終ジャッジ日時 2023-12-19 06:22:54
合計ジャッジ時間 29,099 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
64,072 KB
testcase_01 AC 55 ms
64,200 KB
testcase_02 AC 101 ms
78,328 KB
testcase_03 AC 89 ms
77,816 KB
testcase_04 AC 772 ms
158,104 KB
testcase_05 AC 1,132 ms
196,376 KB
testcase_06 AC 384 ms
107,160 KB
testcase_07 AC 2,174 ms
277,904 KB
testcase_08 AC 3,856 ms
336,748 KB
testcase_09 AC 3,033 ms
319,900 KB
testcase_10 AC 4,596 ms
407,072 KB
testcase_11 MLE -
testcase_12 AC 883 ms
164,376 KB
testcase_13 MLE -
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 for x in range(N)] for v in range(18*N)]
dist[0][Sx][Sy]=0
while queue:
    d,v,x,y=queue.popleft()
    if dist[v][x][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][yy]>d+1:
                dist[vv][xx][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][Gy])
if ans==inf:
    ans=-1
print(ans)
0