結果

問題 No.34 砂漠の行商人
ユーザー titiatitia
提出日時 2022-01-06 02:32:31
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 738 bytes
コンパイル時間 325 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 486,000 KB
最終ジャッジ日時 2024-04-24 06:55:13
合計ジャッジ時間 13,856 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,632 KB
testcase_01 AC 52 ms
61,184 KB
testcase_02 AC 65 ms
68,224 KB
testcase_03 AC 42 ms
54,528 KB
testcase_04 AC 106 ms
81,920 KB
testcase_05 AC 114 ms
82,048 KB
testcase_06 AC 68 ms
69,120 KB
testcase_07 AC 131 ms
85,248 KB
testcase_08 AC 152 ms
91,264 KB
testcase_09 AC 1,538 ms
309,020 KB
testcase_10 AC 245 ms
223,104 KB
testcase_11 AC 2,856 ms
473,016 KB
testcase_12 AC 102 ms
80,860 KB
testcase_13 TLE -
testcase_14 AC 4,067 ms
469,388 KB
testcase_15 AC 101 ms
114,176 KB
testcase_16 AC 250 ms
137,856 KB
testcase_17 AC 100 ms
120,064 KB
testcase_18 AC 90 ms
84,736 KB
testcase_19 AC 1,423 ms
292,224 KB
testcase_20 AC 2,169 ms
327,584 KB
testcase_21 AC 65 ms
72,704 KB
testcase_22 AC 137 ms
146,944 KB
testcase_23 AC 109 ms
127,744 KB
testcase_24 AC 2,693 ms
433,504 KB
testcase_25 AC 164 ms
97,920 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,1800)
x-=1
y-=1
zz-=1
ww-=1
DP=[1<<30]*(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