結果

問題 No.34 砂漠の行商人
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-12-31 22:06:42
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 940 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 440,492 KB
最終ジャッジ日時 2024-04-17 10:03:33
合計ジャッジ時間 17,893 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
59,008 KB
testcase_01 AC 48 ms
60,416 KB
testcase_02 AC 69 ms
70,272 KB
testcase_03 AC 70 ms
71,552 KB
testcase_04 AC 151 ms
82,560 KB
testcase_05 AC 136 ms
82,984 KB
testcase_06 AC 85 ms
76,964 KB
testcase_07 AC 180 ms
87,808 KB
testcase_08 AC 211 ms
92,064 KB
testcase_09 AC 3,735 ms
281,012 KB
testcase_10 AC 3,371 ms
348,008 KB
testcase_11 AC 2,660 ms
419,888 KB
testcase_12 AC 160 ms
82,560 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

n,v,sy,sx,gy,gx = map(int,input().split())
L = [list(map(int,input().split())) for i in range(n)]
sx,sy,gx,gy = sx-1,sy-1,gx-1,gy-1
inf = 10**10
M = min(v,1800)
dp = [[inf]*(n*n) for i in range(M+1)]
dp[M][sx*n+sy] = 0
hlis = [deque() for i in range(M+1)]
hlis[M].append([0,sx*n+sy])
for life in range(M+1)[::-1]:
    h = hlis[life]
    while h:
        d,ind = h.popleft()
        x,y = divmod(ind,n)
        if dp[life][ind] != d:
            continue

        for (i,j) in ((1,0),(-1,0),(0,1),(0,-1)):
            nx = x+i
            ny = y+j
            if 0 <= nx < n and 0 <= ny < n:
                nind = nx*n+ny
                if life > L[nx][ny] and dp[life-L[nx][ny]][nind] > d+1:
                    dp[life-L[nx][ny]][nind] = d+1
                    hlis[life-L[nx][ny]].append([d+1,nind])

ans = inf
for i in range(M+1):
    ans = min(ans,dp[i][gx*n+gy])
if ans == inf:
    ans = -1
print(ans)
0