結果

問題 No.2328 Build Walls
ユーザー nikoro256nikoro256
提出日時 2023-05-28 15:49:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 880 bytes
コンパイル時間 441 ms
コンパイル使用メモリ 87,244 KB
実行使用メモリ 154,272 KB
最終ジャッジ日時 2023-08-27 13:04:24
合計ジャッジ時間 27,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
75,860 KB
testcase_01 AC 82 ms
71,132 KB
testcase_02 AC 81 ms
71,412 KB
testcase_03 AC 81 ms
71,332 KB
testcase_04 AC 83 ms
71,344 KB
testcase_05 AC 83 ms
71,224 KB
testcase_06 AC 81 ms
71,256 KB
testcase_07 AC 83 ms
71,292 KB
testcase_08 AC 82 ms
71,228 KB
testcase_09 AC 82 ms
71,448 KB
testcase_10 AC 83 ms
71,400 KB
testcase_11 AC 80 ms
71,204 KB
testcase_12 AC 82 ms
71,220 KB
testcase_13 AC 200 ms
83,652 KB
testcase_14 AC 1,418 ms
103,408 KB
testcase_15 AC 671 ms
84,728 KB
testcase_16 AC 187 ms
78,544 KB
testcase_17 AC 433 ms
82,496 KB
testcase_18 AC 154 ms
77,980 KB
testcase_19 AC 90 ms
76,696 KB
testcase_20 AC 172 ms
78,220 KB
testcase_21 AC 115 ms
80,576 KB
testcase_22 AC 2,786 ms
154,272 KB
testcase_23 AC 2,239 ms
107,804 KB
testcase_24 AC 1,834 ms
102,108 KB
testcase_25 AC 2,193 ms
106,956 KB
testcase_26 AC 1,130 ms
93,648 KB
testcase_27 AC 1,627 ms
98,764 KB
testcase_28 AC 138 ms
86,504 KB
testcase_29 AC 2,262 ms
109,720 KB
testcase_30 AC 240 ms
89,604 KB
testcase_31 AC 195 ms
88,832 KB
testcase_32 AC 1,582 ms
97,352 KB
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][0]!=-1:
            heapq.heappush(hq,[A[i][0],(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][y]!=-1 and high[x*W+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*W+W-1]!=-1:
        ans=min(ans,dist[i*W+W-1])
if ans>=10**12:
    print(-1)
else:
    print(ans)
0