結果

問題 No.2328 Build Walls
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2023-05-28 15:23:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,377 ms / 3,000 ms
コード長 855 bytes
コンパイル時間 517 ms
コンパイル使用メモリ 86,900 KB
実行使用メモリ 92,612 KB
最終ジャッジ日時 2023-08-27 12:04:45
合計ジャッジ時間 16,383 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,140 KB
testcase_01 AC 80 ms
70,976 KB
testcase_02 AC 80 ms
71,336 KB
testcase_03 AC 80 ms
71,392 KB
testcase_04 AC 81 ms
71,416 KB
testcase_05 AC 83 ms
71,392 KB
testcase_06 AC 81 ms
71,092 KB
testcase_07 AC 82 ms
71,308 KB
testcase_08 AC 82 ms
71,224 KB
testcase_09 AC 81 ms
71,236 KB
testcase_10 AC 81 ms
71,312 KB
testcase_11 AC 81 ms
71,124 KB
testcase_12 AC 81 ms
70,928 KB
testcase_13 AC 204 ms
83,552 KB
testcase_14 AC 471 ms
82,384 KB
testcase_15 AC 380 ms
81,552 KB
testcase_16 AC 190 ms
78,952 KB
testcase_17 AC 345 ms
82,480 KB
testcase_18 AC 149 ms
78,444 KB
testcase_19 AC 93 ms
75,772 KB
testcase_20 AC 176 ms
78,328 KB
testcase_21 AC 123 ms
79,652 KB
testcase_22 AC 662 ms
85,392 KB
testcase_23 AC 1,020 ms
91,432 KB
testcase_24 AC 951 ms
90,892 KB
testcase_25 AC 1,032 ms
91,712 KB
testcase_26 AC 741 ms
90,340 KB
testcase_27 AC 914 ms
90,664 KB
testcase_28 AC 145 ms
81,216 KB
testcase_29 AC 1,028 ms
91,656 KB
testcase_30 AC 238 ms
89,204 KB
testcase_31 AC 213 ms
88,800 KB
testcase_32 AC 885 ms
90,396 KB
testcase_33 AC 1,377 ms
92,612 KB
testcase_34 AC 233 ms
88,880 KB
testcase_35 AC 1,147 ms
91,132 KB
testcase_36 AC 81 ms
71,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
h,w = map(int,input().split())
A = [list(map(int,input().split())) for i in range(h-2)]

inf = 10**10
dist = [[inf]*w for i in range(h-2)]

H = []
for i in range(h-2):
    if A[i][0] != -1:
        dist[i][0] = A[i][0]
        heappush(H,[A[i][0],i,0])


while H:
    dis,x,y = heappop(H)
    if dist[x][y] != dis:
        continue

    for dx in range(-1,2):
        for dy in range(-1,2):
            if dx == 0 and dy == 0:
                continue
            nx = x+dx
            ny = y+dy
            if 0 <= nx < h-2 and 0 <= ny < w and A[nx][ny] != -1:
                nd = dis + A[nx][ny]
                if nd < dist[nx][ny]:
                    dist[nx][ny] = nd
                    heappush(H,[nd,nx,ny])


ans = inf
for i in range(h-2):
    ans = min(ans,dist[i][-1])
if ans == inf:
    ans = -1
print(ans)
0