結果

問題 No.2328 Build Walls
ユーザー nikoro256nikoro256
提出日時 2023-05-28 15:53:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 940 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 86,684 KB
実行使用メモリ 150,432 KB
最終ジャッジ日時 2023-08-27 13:15:38
合計ジャッジ時間 27,596 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,308 KB
testcase_01 WA -
testcase_02 AC 75 ms
71,288 KB
testcase_03 AC 74 ms
71,444 KB
testcase_04 AC 75 ms
71,376 KB
testcase_05 AC 75 ms
71,352 KB
testcase_06 AC 74 ms
71,180 KB
testcase_07 AC 77 ms
71,344 KB
testcase_08 WA -
testcase_09 AC 74 ms
71,188 KB
testcase_10 AC 75 ms
71,300 KB
testcase_11 AC 74 ms
71,208 KB
testcase_12 WA -
testcase_13 AC 205 ms
83,824 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 95 ms
78,060 KB
testcase_20 WA -
testcase_21 AC 120 ms
82,816 KB
testcase_22 AC 2,531 ms
150,432 KB
testcase_23 AC 2,200 ms
109,544 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 140 ms
87,292 KB
testcase_29 WA -
testcase_30 AC 221 ms
88,848 KB
testcase_31 AC 200 ms
88,488 KB
testcase_32 WA -
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

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]!=-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)
0