結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 20 ms
8,684 KB
testcase_01 AC 20 ms
8,668 KB
testcase_02 AC 55 ms
8,768 KB
testcase_03 AC 19 ms
8,808 KB
testcase_04 AC 776 ms
11,936 KB
testcase_05 AC 770 ms
12,392 KB
testcase_06 AC 58 ms
8,732 KB
testcase_07 AC 1,275 ms
14,416 KB
testcase_08 AC 1,760 ms
18,084 KB
testcase_09 AC 20 ms
8,676 KB
testcase_10 AC 21 ms
8,632 KB
testcase_11 AC 21 ms
8,604 KB
testcase_12 AC 487 ms
12,020 KB
testcase_13 AC 20 ms
8,800 KB
testcase_14 AC 21 ms
8,684 KB
testcase_15 AC 19 ms
8,532 KB
testcase_16 AC 20 ms
8,688 KB
testcase_17 AC 138 ms
62,772 KB
testcase_18 AC 19 ms
8,552 KB
testcase_19 TLE -
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)]

if V>1800:
    print(abs(x-zz)+abs(y-ww))
    exit()

x,y=y,x
zz,ww=ww,zz
x-=1
y-=1
zz-=1
ww-=1
DP=[300]*(N*N*(V+1))

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

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

while Q:
    now,power,xy=Q.popleft()
    if xy==zz*N+ww:
        print(now)
        break

    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)*N*N+nec]>now+1:
                DP[(power-dec)*N*N+nec]=now+1
                Q.append((now+1,power-dec,nec))

else:
    print(-1)
0