結果
問題 |
No.2328 Build Walls
|
ユーザー |
![]() |
提出日時 | 2023-04-13 11:35:07 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 629 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 136,880 KB |
最終ジャッジ日時 | 2024-10-09 10:30:53 |
合計ジャッジ時間 | 23,678 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 TLE * 1 -- * 3 |
ソースコード
import heapq h, w = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(h-2)] inf = 1 << 30 dist = [[inf] * w for _ in range(h-2)] hq = [] for i in range(h-2): if a[i][0] == -1: continue heapq.heappush(hq, [a[i][0], i, 0]) while hq: d, x, y = heapq.heappop(hq) if y == w - 1: print(d) exit() if dist[x][y] <= d: continue dist[x][y] = d for p in range(max(0, x-1), min(h-2, x+2)): for q in range(max(0, y-1), min(w, y+2)): if a[p][q] == -1: continue if dist[p][q] <= d + a[p][q]: continue heapq.heappush(hq, [d+a[p][q], p, q]) print(-1)