結果

問題 No.34 砂漠の行商人
ユーザー titiatitia
提出日時 2022-01-06 02:37:53
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 746 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 850,748 KB
最終ジャッジ日時 2024-04-24 06:59:34
合計ジャッジ時間 6,070 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
54,144 KB
testcase_01 AC 52 ms
61,056 KB
testcase_02 AC 63 ms
68,352 KB
testcase_03 AC 47 ms
54,016 KB
testcase_04 AC 113 ms
81,488 KB
testcase_05 AC 110 ms
82,048 KB
testcase_06 AC 64 ms
69,552 KB
testcase_07 AC 130 ms
85,168 KB
testcase_08 AC 165 ms
91,008 KB
testcase_09 MLE -
testcase_10 MLE -
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)]

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

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