結果
| 問題 |
No.2328 Build Walls
|
| コンテスト | |
| ユーザー |
nikoro256
|
| 提出日時 | 2023-05-28 15:17:53 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 814 bytes |
| コンパイル時間 | 642 ms |
| コンパイル使用メモリ | 82,688 KB |
| 実行使用メモリ | 199,260 KB |
| 最終ジャッジ日時 | 2024-12-27 05:53:19 |
| 合計ジャッジ時間 | 35,504 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 12 TLE * 4 |
ソースコード
import heapq
ds=[[0,1],[1,1],[-1,1],[1,0],[-1,0]]
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)] for _ in range(H)]
while len(hq)!=0:
h,p=heapq.heappop(hq)
if high[p[0]][p[1]]==-1:
high[p[0]][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:
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][-1]!=-1:
ans=min(ans,dist[i][-1])
if ans>=10**12:
print(-1)
else:
print(ans)
nikoro256