結果
問題 |
No.2328 Build Walls
|
ユーザー |
![]() |
提出日時 | 2023-05-28 15:34:54 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 844 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 82,456 KB |
実行使用メモリ | 192,512 KB |
最終ジャッジ日時 | 2024-12-27 07:30:05 |
合計ジャッジ時間 | 29,074 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 TLE * 2 |
ソースコード
import heapq ds=[[0,1],[1,1],[-1,1],[1,0],[-1,0],[0,-1],[1,-1],[-1,-1]] def daiku(): hq=[] for i in range(H-2): if A[i][0]!=-1: heapq.heappush(hq,[A[i][0],(i,0)]) high=[-1 for _ in range(W*H)] while len(hq)!=0: h,p=heapq.heappop(hq) if high[p[0]*W+p[1]]==-1: high[p[0]*W+p[1]]=h for dx,dy in ds: x,y=p x+=dx y+=dy if 0<=x<H-2 and 0<=y<W and A[x][y]!=-1 and high[x*W+y]==-1: heapq.heappush(hq,[h+A[x][y],(x,y)]) return high H,W=map(int,input().split()) A=[] for i in range(H-2): A.append(list(map(int,input().split()))) dist=daiku() ans=10**12 for i in range(H-2): if dist[i*W+W-1]!=-1: ans=min(ans,dist[i*W+W-1]) if ans>=10**12: print(-1) else: print(ans)