結果

問題 No.2328 Build Walls
ユーザー nikoro256nikoro256
提出日時 2023-05-28 15:58:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,899 ms / 3,000 ms
コード長 1,025 bytes
コンパイル時間 1,330 ms
コンパイル使用メモリ 86,756 KB
実行使用メモリ 101,208 KB
最終ジャッジ日時 2023-08-27 13:29:58
合計ジャッジ時間 17,026 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,172 KB
testcase_01 AC 77 ms
71,348 KB
testcase_02 AC 77 ms
71,332 KB
testcase_03 AC 77 ms
71,324 KB
testcase_04 AC 78 ms
71,204 KB
testcase_05 AC 77 ms
71,296 KB
testcase_06 AC 78 ms
71,304 KB
testcase_07 AC 77 ms
71,272 KB
testcase_08 AC 77 ms
71,188 KB
testcase_09 AC 78 ms
71,128 KB
testcase_10 AC 77 ms
71,452 KB
testcase_11 AC 76 ms
71,252 KB
testcase_12 AC 77 ms
71,364 KB
testcase_13 AC 185 ms
86,244 KB
testcase_14 AC 456 ms
83,516 KB
testcase_15 AC 344 ms
82,712 KB
testcase_16 AC 174 ms
79,004 KB
testcase_17 AC 330 ms
83,396 KB
testcase_18 AC 129 ms
77,892 KB
testcase_19 AC 87 ms
76,628 KB
testcase_20 AC 160 ms
79,012 KB
testcase_21 AC 114 ms
83,132 KB
testcase_22 AC 692 ms
87,840 KB
testcase_23 AC 1,018 ms
96,956 KB
testcase_24 AC 948 ms
96,352 KB
testcase_25 AC 978 ms
96,548 KB
testcase_26 AC 719 ms
95,456 KB
testcase_27 AC 871 ms
96,136 KB
testcase_28 AC 138 ms
91,608 KB
testcase_29 AC 1,023 ms
97,404 KB
testcase_30 AC 206 ms
93,712 KB
testcase_31 AC 193 ms
93,580 KB
testcase_32 AC 873 ms
95,972 KB
testcase_33 AC 1,899 ms
101,208 KB
testcase_34 AC 223 ms
93,936 KB
testcase_35 AC 1,535 ms
98,016 KB
testcase_36 AC 77 ms
71,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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][0]!=-1:
            heapq.heappush(hq,[A[i][0],(i,0)])
    high=[-1 for _ in range(W*H)]
    karidist=[10**9 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:
                    if karidist[x*W+y]>h+A[x][y]:
                        karidist[x*W+y]=h+A[x][y]
                        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)
0