結果
問題 | No.2328 Build Walls |
ユーザー |
![]() |
提出日時 | 2023-04-13 11:45:25 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,913 ms / 3,000 ms |
コード長 | 793 bytes |
コンパイル時間 | 209 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 88,972 KB |
最終ジャッジ日時 | 2024-10-09 10:24:59 |
合計ジャッジ時間 | 16,862 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 |
ソースコード
import heapq h, w = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(h-2)] def c(d, x, y): global h, w return d*h*w + x*w + y def dc(num): global h, w yield num // (h * w) num %= (h * w) yield num // w yield num % w 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, c(a[i][0], i, 0)) while hq: d, x, y = dc(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, c(d+a[p][q], p, q)) print(-1)