結果

問題 No.34 砂漠の行商人
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2021-12-31 21:43:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 800 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 82,320 KB
実行使用メモリ 318,268 KB
最終ジャッジ日時 2024-04-17 09:35:58
合計ジャッジ時間 10,052 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
318,268 KB
testcase_01 AC 42 ms
61,036 KB
testcase_02 AC 100 ms
76,396 KB
testcase_03 AC 134 ms
76,920 KB
testcase_04 AC 446 ms
85,428 KB
testcase_05 AC 444 ms
85,044 KB
testcase_06 AC 93 ms
77,060 KB
testcase_07 AC 682 ms
91,400 KB
testcase_08 AC 940 ms
102,284 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
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 heapq import heappush,heappop
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,2000)
dp = [[inf]*(n*n) for i in range(M+1)]
dp[M][sx*n+sy] = 0
h = [[0,M,sx*n+sy]]
while h:
    d,life,ind = heappop(h)
    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
                heappush(h,[d+1,life-L[nx][ny],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