結果

問題 No.34 砂漠の行商人
ユーザー titiatitia
提出日時 2022-01-06 02:27:03
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 739 bytes
コンパイル時間 280 ms
コンパイル使用メモリ 82,256 KB
実行使用メモリ 537,012 KB
最終ジャッジ日時 2024-04-24 06:48:28
合計ジャッジ時間 14,448 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,016 KB
testcase_01 AC 48 ms
60,672 KB
testcase_02 AC 62 ms
68,864 KB
testcase_03 AC 41 ms
54,400 KB
testcase_04 AC 107 ms
81,536 KB
testcase_05 AC 110 ms
81,920 KB
testcase_06 AC 64 ms
68,992 KB
testcase_07 AC 139 ms
85,248 KB
testcase_08 AC 161 ms
91,264 KB
testcase_09 AC 1,757 ms
325,092 KB
testcase_10 AC 300 ms
239,288 KB
testcase_11 MLE -
testcase_12 AC 97 ms
81,024 KB
testcase_13 MLE -
testcase_14 MLE -
testcase_15 AC 138 ms
113,408 KB
testcase_16 AC 283 ms
142,464 KB
testcase_17 AC 104 ms
113,408 KB
testcase_18 AC 90 ms
86,016 KB
testcase_19 AC 1,298 ms
286,464 KB
testcase_20 AC 2,316 ms
328,268 KB
testcase_21 AC 65 ms
72,576 KB
testcase_22 AC 146 ms
147,200 KB
testcase_23 AC 127 ms
135,936 KB
testcase_24 AC 3,049 ms
496,880 KB
testcase_25 AC 185 ms
97,664 KB
権限があれば一括ダウンロードができます

ソースコード

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

else:
    print(-1)

                
0