結果
問題 |
No.34 砂漠の行商人
|
ユーザー |
![]() |
提出日時 | 2015-08-15 04:50:43 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 911 bytes |
コンパイル時間 | 154 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 176,872 KB |
最終ジャッジ日時 | 2024-07-18 09:33:44 |
合計ジャッジ時間 | 11,277 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 9 TLE * 1 -- * 16 |
ソースコード
from collections import defaultdict import heapq def solve(): N, V, Sx, Sy, Gx, Gy = list(map(int, input().split())) L = [] for i in range(N): L.append(list(map(int, input().split()))) Sy -= 1 Sx -= 1 Gy -= 1 Gx -= 1 dy = (-1, 0, 1, 0) dx = (0, -1, 0, 1) dist = defaultdict(lambda: float('inf')) hq = [] heapq.heappush(hq, (0, Sy, Sx, V)) while hq: n, y, x, v = heapq.heappop(hq) if y == Gy and x == Gx: print(n) return for d in range(4): ny = y + dy[d] nx = x + dx[d] if 0 <= nx < N and 0 <= ny < N and L[ny][nx] < v: nv = v - L[ny][nx] if dist[ny, nx, nv] > n + 1: dist[ny, nx, nv] = n + 1 heapq.heappush(hq, (n + 1, ny, nx, nv)) print(-1) if __name__ == '__main__': solve()