結果

問題 No.34 砂漠の行商人
ユーザー titiatitia
提出日時 2022-01-06 02:38:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,148 ms / 5,000 ms
コード長 776 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 328,108 KB
最終ジャッジ日時 2024-04-24 06:59:53
合計ジャッジ時間 6,174 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,016 KB
testcase_01 AC 53 ms
60,928 KB
testcase_02 AC 64 ms
68,864 KB
testcase_03 AC 46 ms
54,528 KB
testcase_04 AC 106 ms
81,664 KB
testcase_05 AC 112 ms
82,048 KB
testcase_06 AC 63 ms
69,760 KB
testcase_07 AC 127 ms
85,120 KB
testcase_08 AC 151 ms
91,392 KB
testcase_09 AC 47 ms
60,544 KB
testcase_10 AC 46 ms
61,184 KB
testcase_11 AC 47 ms
61,056 KB
testcase_12 AC 91 ms
80,968 KB
testcase_13 AC 46 ms
60,672 KB
testcase_14 AC 45 ms
60,928 KB
testcase_15 AC 44 ms
60,032 KB
testcase_16 AC 46 ms
60,160 KB
testcase_17 AC 100 ms
120,064 KB
testcase_18 AC 44 ms
54,144 KB
testcase_19 AC 1,229 ms
292,352 KB
testcase_20 AC 2,148 ms
328,108 KB
testcase_21 AC 67 ms
72,576 KB
testcase_22 AC 140 ms
147,072 KB
testcase_23 AC 45 ms
60,176 KB
testcase_24 AC 47 ms
61,184 KB
testcase_25 AC 166 ms
98,224 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)]

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