結果

問題 No.34 砂漠の行商人
ユーザー titiatitia
提出日時 2022-01-06 02:25:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 761 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 11,088 KB
実行使用メモリ 110,324 KB
最終ジャッジ日時 2023-08-06 10:52:44
合計ジャッジ時間 11,457 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,736 KB
testcase_01 AC 20 ms
8,624 KB
testcase_02 AC 49 ms
8,744 KB
testcase_03 AC 122 ms
9,064 KB
testcase_04 AC 694 ms
12,156 KB
testcase_05 AC 687 ms
12,740 KB
testcase_06 AC 62 ms
8,820 KB
testcase_07 AC 1,138 ms
14,404 KB
testcase_08 AC 1,561 ms
18,180 KB
testcase_09 TLE -
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
input = sys.stdin.readline
from collections import deque

N,V,x,y,zz,ww=map(int,input().split())
MAP=[list(map(int,input().split())) for i in range(N)]

x,y=y,x
zz,ww=ww,zz
V=min(V,2000)
x-=1
y-=1
zz-=1
ww-=1
DP=[[1<<30]*(N*N) for i in range(V+1)]

DP[V][x*N+y]=0

Q=deque()
Q.append((0,V,x*N+y))

while Q:
    now,power,xy=Q.popleft()

    x=xy//N
    y=xy%N

    for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]:
        if 0<=z<N and 0<=w<N:
            nec=z*N+w
            dec=MAP[z][w]

            if power-dec>0 and DP[power-dec][nec]>now+1:
                DP[power-dec][nec]=now+1
                Q.append((now+1,power-dec,nec))

ANS=1<<30
for i in range(V+1):
    ANS=min(ANS,DP[i][zz*N+ww])

if ANS==1<<30:
    print(-1)
else:
    print(ANS)
0