結果
| 問題 |
No.34 砂漠の行商人
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2022-01-06 02:27:54 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 720 bytes |
| コンパイル時間 | 190 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 114,596 KB |
| 最終ジャッジ日時 | 2024-11-06 13:58:07 |
| 合計ジャッジ時間 | 11,486 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 TLE * 1 -- * 16 |
ソースコード
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)
titia