結果

問題 No.2328 Build Walls
ユーザー dangodango
提出日時 2023-06-13 21:31:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,587 ms / 3,000 ms
コード長 714 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,164 KB
実行使用メモリ 129,256 KB
最終ジャッジ日時 2023-09-04 08:41:15
合計ジャッジ時間 17,692 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,508 KB
testcase_01 AC 94 ms
71,612 KB
testcase_02 AC 94 ms
71,672 KB
testcase_03 AC 97 ms
71,548 KB
testcase_04 AC 97 ms
71,568 KB
testcase_05 AC 95 ms
71,448 KB
testcase_06 AC 95 ms
71,616 KB
testcase_07 AC 96 ms
71,612 KB
testcase_08 AC 93 ms
71,448 KB
testcase_09 AC 94 ms
71,616 KB
testcase_10 AC 92 ms
71,652 KB
testcase_11 AC 94 ms
71,492 KB
testcase_12 AC 94 ms
71,612 KB
testcase_13 AC 157 ms
82,812 KB
testcase_14 AC 330 ms
86,400 KB
testcase_15 AC 266 ms
83,476 KB
testcase_16 AC 163 ms
78,472 KB
testcase_17 AC 382 ms
87,024 KB
testcase_18 AC 116 ms
77,572 KB
testcase_19 AC 107 ms
76,764 KB
testcase_20 AC 130 ms
77,608 KB
testcase_21 AC 134 ms
78,908 KB
testcase_22 AC 400 ms
90,068 KB
testcase_23 AC 1,458 ms
122,048 KB
testcase_24 AC 1,289 ms
120,552 KB
testcase_25 AC 1,587 ms
129,256 KB
testcase_26 AC 1,161 ms
115,236 KB
testcase_27 AC 1,323 ms
115,012 KB
testcase_28 AC 159 ms
82,200 KB
testcase_29 AC 1,467 ms
118,712 KB
testcase_30 AC 192 ms
88,892 KB
testcase_31 AC 192 ms
89,176 KB
testcase_32 AC 1,279 ms
119,636 KB
testcase_33 AC 350 ms
93,416 KB
testcase_34 AC 200 ms
88,984 KB
testcase_35 AC 351 ms
92,576 KB
testcase_36 AC 96 ms
71,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
H, W = map(int, input().split())
H -= 2
A = [list(map(int, input().split())) + [-1] for _ in range(H)] + [[-1] * (W + 1)]
INF = 10 ** 18
dp = [[INF] * (W + 1) for _ in range(H)] + [[INF] * (W + 1)]
que = collections.deque()
for i in range(H):
    if A[i][0] == -1:
        continue
    dp[i][0] = A[i][0]
    que.append((i, 0))
while que:
    X, Y = que.popleft()
    for i in range(-1, 2):
        for j in range(-1, 2):
            SX = X + i
            SY = Y + j
            if A[SX][SY] != -1 and dp[SX][SY] > dp[X][Y] + A[SX][SY]:
                dp[SX][SY] = dp[X][Y] + A[SX][SY]
                que.append((SX, SY))
print(min(v[-2] for v in dp) if min(v[-2] for v in dp) < INF else -1)
0