結果

問題 No.2328 Build Walls
ユーザー nikoro256nikoro256
提出日時 2023-05-28 15:17:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 277 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 164,888 KB
最終ジャッジ日時 2023-08-27 11:53:05
合計ジャッジ時間 28,814 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,508 KB
testcase_01 AC 73 ms
71,208 KB
testcase_02 AC 74 ms
71,236 KB
testcase_03 AC 77 ms
71,388 KB
testcase_04 AC 77 ms
71,604 KB
testcase_05 AC 75 ms
71,412 KB
testcase_06 AC 73 ms
71,300 KB
testcase_07 AC 74 ms
71,312 KB
testcase_08 AC 77 ms
71,328 KB
testcase_09 AC 75 ms
71,308 KB
testcase_10 AC 75 ms
71,156 KB
testcase_11 AC 74 ms
71,608 KB
testcase_12 AC 76 ms
71,408 KB
testcase_13 AC 174 ms
83,792 KB
testcase_14 WA -
testcase_15 AC 763 ms
85,840 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 87 ms
76,104 KB
testcase_20 WA -
testcase_21 AC 121 ms
79,608 KB
testcase_22 TLE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 141 ms
81,420 KB
testcase_29 WA -
testcase_30 AC 221 ms
89,244 KB
testcase_31 AC 201 ms
88,608 KB
testcase_32 WA -
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0