結果

問題 No.34 砂漠の行商人
ユーザー titiatitia
提出日時 2022-01-06 02:22:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 741 bytes
コンパイル時間 516 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 346,048 KB
最終ジャッジ日時 2024-04-24 06:42:37
合計ジャッジ時間 28,904 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,144 KB
testcase_01 AC 46 ms
61,184 KB
testcase_02 AC 61 ms
68,992 KB
testcase_03 AC 77 ms
76,544 KB
testcase_04 AC 108 ms
81,920 KB
testcase_05 AC 108 ms
81,920 KB
testcase_06 AC 65 ms
70,144 KB
testcase_07 AC 134 ms
85,120 KB
testcase_08 AC 155 ms
91,520 KB
testcase_09 AC 1,848 ms
286,720 KB
testcase_10 AC 2,086 ms
267,264 KB
testcase_11 WA -
testcase_12 AC 112 ms
81,664 KB
testcase_13 AC 3,201 ms
346,048 KB
testcase_14 AC 3,124 ms
340,268 KB
testcase_15 AC 792 ms
216,192 KB
testcase_16 AC 757 ms
203,520 KB
testcase_17 AC 1,780 ms
284,552 KB
testcase_18 AC 181 ms
89,344 KB
testcase_19 AC 1,520 ms
286,720 KB
testcase_20 AC 2,983 ms
329,140 KB
testcase_21 AC 68 ms
72,832 KB
testcase_22 AC 3,016 ms
324,292 KB
testcase_23 AC 1,163 ms
272,272 KB
testcase_24 AC 3,053 ms
330,576 KB
testcase_25 AC 235 ms
103,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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,1000)
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