結果

問題 No.2328 Build Walls
ユーザー nikoro256nikoro256
提出日時 2023-05-28 15:34:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 844 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 87,040 KB
実行使用メモリ 154,420 KB
最終ジャッジ日時 2023-08-27 12:28:20
合計ジャッジ時間 27,444 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,680 KB
testcase_01 AC 78 ms
71,228 KB
testcase_02 AC 80 ms
71,416 KB
testcase_03 AC 76 ms
71,464 KB
testcase_04 AC 76 ms
71,428 KB
testcase_05 AC 77 ms
71,328 KB
testcase_06 AC 76 ms
71,444 KB
testcase_07 AC 78 ms
71,184 KB
testcase_08 AC 80 ms
71,508 KB
testcase_09 AC 76 ms
71,456 KB
testcase_10 AC 75 ms
71,416 KB
testcase_11 AC 75 ms
71,020 KB
testcase_12 AC 74 ms
71,028 KB
testcase_13 AC 194 ms
84,108 KB
testcase_14 AC 1,358 ms
104,184 KB
testcase_15 AC 655 ms
84,760 KB
testcase_16 AC 175 ms
78,704 KB
testcase_17 AC 420 ms
82,424 KB
testcase_18 AC 140 ms
78,068 KB
testcase_19 AC 85 ms
76,368 KB
testcase_20 AC 158 ms
78,376 KB
testcase_21 AC 113 ms
81,564 KB
testcase_22 AC 2,588 ms
154,420 KB
testcase_23 AC 2,191 ms
108,448 KB
testcase_24 AC 1,818 ms
102,340 KB
testcase_25 AC 2,130 ms
106,372 KB
testcase_26 AC 1,159 ms
93,852 KB
testcase_27 AC 1,648 ms
98,992 KB
testcase_28 AC 138 ms
86,508 KB
testcase_29 AC 2,228 ms
110,220 KB
testcase_30 AC 233 ms
89,276 KB
testcase_31 AC 192 ms
88,672 KB
testcase_32 AC 1,543 ms
98,196 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
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