結果
| 問題 |
No.2328 Build Walls
|
| コンテスト | |
| ユーザー |
nikoro256
|
| 提出日時 | 2023-05-28 15:53:40 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 940 bytes |
| コンパイル時間 | 414 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 174,208 KB |
| 最終ジャッジ日時 | 2024-12-27 09:27:08 |
| 合計ジャッジ時間 | 31,372 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 17 WA * 15 TLE * 2 |
ソースコード
import heapq
import sys
input=sys.stdin.readline
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]!=-1:
heapq.heappush(hq,[A[i*W],(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*W+y]!=-1 and high[x*W+y]==-1:
heapq.heappush(hq,[h+A[x*W+y],(x,y)])
return high
H,W=map(int,input().split())
A=[0 for _ in range(H*W)]
for i in range(H-2):
A_d=list(map(int,input().split()))
for j in range(W):
A[i*W+j]=A_d[j]
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)
nikoro256