結果

問題 No.2328 Build Walls
ユーザー googol_S0googol_S0
提出日時 2023-05-28 14:03:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,199 ms / 3,000 ms
コード長 755 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 87,288 KB
実行使用メモリ 91,464 KB
最終ジャッジ日時 2023-08-27 08:57:18
合計ジャッジ時間 15,398 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,044 KB
testcase_01 AC 80 ms
71,140 KB
testcase_02 AC 79 ms
71,044 KB
testcase_03 AC 80 ms
70,756 KB
testcase_04 AC 80 ms
70,656 KB
testcase_05 AC 79 ms
70,736 KB
testcase_06 AC 77 ms
70,736 KB
testcase_07 AC 78 ms
70,976 KB
testcase_08 AC 81 ms
71,192 KB
testcase_09 AC 79 ms
71,144 KB
testcase_10 AC 77 ms
71,252 KB
testcase_11 AC 78 ms
71,016 KB
testcase_12 AC 80 ms
71,264 KB
testcase_13 AC 191 ms
83,228 KB
testcase_14 AC 422 ms
81,824 KB
testcase_15 AC 337 ms
80,784 KB
testcase_16 AC 164 ms
78,316 KB
testcase_17 AC 311 ms
81,320 KB
testcase_18 AC 131 ms
78,000 KB
testcase_19 AC 104 ms
77,812 KB
testcase_20 AC 149 ms
78,640 KB
testcase_21 AC 146 ms
80,948 KB
testcase_22 AC 595 ms
85,176 KB
testcase_23 AC 939 ms
90,468 KB
testcase_24 AC 878 ms
90,452 KB
testcase_25 AC 968 ms
90,780 KB
testcase_26 AC 696 ms
89,352 KB
testcase_27 AC 825 ms
91,080 KB
testcase_28 AC 177 ms
88,328 KB
testcase_29 AC 988 ms
90,788 KB
testcase_30 AC 227 ms
88,464 KB
testcase_31 AC 215 ms
88,516 KB
testcase_32 AC 816 ms
89,796 KB
testcase_33 AC 1,199 ms
91,464 KB
testcase_34 AC 252 ms
88,700 KB
testcase_35 AC 1,039 ms
90,756 KB
testcase_36 AC 78 ms
71,040 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
H-=2
A=[list(map(int,input().split())) for i in range(H)]
INF=10**10
for i in range(H):
    for j in range(W):
        if A[i][j]==-1:
            A[i][j]=INF
from heapq import *
D=[[INF]*W for i in range(H)]
Q=[]
heapify(Q)
for i in range(H):
    heappush(Q,(A[i][0],i,0))
    D[i][0]=A[i][0]
while len(Q):
    v=heappop(Q)
    x,y=v[1],v[2]
    if v[0]>D[x][y]:
        continue
    for i in range(-1,2):
        for j in range(-1,2):
            p,q=x+i,y+j
            if 0<=p and 0<=q and p<H and q<W:
                if D[x][y]+A[p][q]<D[p][q]:
                    D[p][q]=D[x][y]+A[p][q]
                    heappush(Q,(D[p][q],p,q))
ANS=min([D[i][-1] for i in range(H)])
if ANS<INF:
    print(ANS)
else:
    print(-1)
0