結果

問題 No.34 砂漠の行商人
ユーザー roarisroaris
提出日時 2020-07-25 22:59:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,234 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 10,932 KB
実行使用メモリ 780,020 KB
最終ジャッジ日時 2023-09-10 02:07:30
合計ジャッジ時間 20,100 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
13,124 KB
testcase_01 MLE -
testcase_02 AC 87 ms
11,172 KB
testcase_03 AC 165 ms
13,912 KB
testcase_04 AC 1,473 ms
61,332 KB
testcase_05 AC 1,762 ms
73,356 KB
testcase_06 AC 100 ms
11,772 KB
testcase_07 AC 2,763 ms
108,532 KB
testcase_08 AC 4,656 ms
175,960 KB
testcase_09 AC 20 ms
8,828 KB
testcase_10 AC 21 ms
8,780 KB
testcase_11 AC 20 ms
8,864 KB
testcase_12 AC 1,411 ms
59,932 KB
testcase_13 AC 20 ms
8,752 KB
testcase_14 AC 21 ms
8,824 KB
testcase_15 AC 19 ms
8,836 KB
testcase_16 AC 19 ms
8,660 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import deque

def bfs():
    dist = [-1]*c
    dist[serial[Sx][Sy][V]] = 0
    q = deque([serial[Sx][Sy][V]])
    
    while q:
        v = q.popleft()
        
        for nv in G[v]:
            if dist[nv]==-1:
                dist[nv] = dist[v]+1
                q.append(nv)
    
    return dist

N, V, Sy, Sx, Gy, Gx = map(int, input().split())
Sy -= 1
Sx -= 1
Gy -= 1
Gx -= 1
L = [list(map(int, input().split())) for _ in range(N)]

if V>=1800:
    print(abs(Sx-Gx)+abs(Sy-Gy))
    exit()

serial = [[[-1]*(V+1) for _ in range(N)] for _ in range(N)]
c = 0

for i in range(N):
    for j in range(N):
        for k in range(V+1):
            serial[i][j][k] = c
            c += 1

G = [[] for _ in range(c)]

for i in range(N):
    for j in range(N):
        for k in range(V+1):
            for ni, nj in [(i-1, j), (i+1, j), (i, j-1), (i, j+1)]:
                if 0<=ni<N and 0<=nj<N and k-L[ni][nj]>0:
                    G[serial[i][j][k]].append(serial[ni][nj][k-L[ni][nj]])

dist = bfs()
ans = 10**18

for i in range(V+1):
    if dist[serial[Gx][Gy][i]]!=-1:
        ans = min(ans, dist[serial[Gx][Gy][i]])
        
if ans==10**18:
    print(-1)
else:
    print(ans)
0