結果
問題 |
No.34 砂漠の行商人
|
ユーザー |
|
提出日時 | 2021-12-31 22:05:51 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 940 bytes |
コンパイル時間 | 334 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 482,964 KB |
最終ジャッジ日時 | 2024-10-09 03:39:05 |
合計ジャッジ時間 | 8,328 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 TLE * 1 -- * 12 |
ソースコード
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,2000) 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)