結果

問題 No.2328 Build Walls
ユーザー masa_aamasa_aa
提出日時 2023-05-28 15:09:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,604 ms / 3,000 ms
コード長 729 bytes
コンパイル時間 442 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 129,632 KB
最終ジャッジ日時 2023-08-27 11:32:51
合計ジャッジ時間 16,748 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
71,912 KB
testcase_01 AC 88 ms
71,504 KB
testcase_02 AC 87 ms
71,692 KB
testcase_03 AC 87 ms
71,464 KB
testcase_04 AC 88 ms
71,704 KB
testcase_05 AC 94 ms
71,336 KB
testcase_06 AC 88 ms
71,368 KB
testcase_07 AC 92 ms
71,760 KB
testcase_08 AC 90 ms
71,700 KB
testcase_09 AC 89 ms
71,776 KB
testcase_10 AC 88 ms
71,680 KB
testcase_11 AC 87 ms
71,392 KB
testcase_12 AC 88 ms
71,636 KB
testcase_13 AC 156 ms
83,356 KB
testcase_14 AC 322 ms
86,644 KB
testcase_15 AC 263 ms
83,760 KB
testcase_16 AC 160 ms
78,884 KB
testcase_17 AC 389 ms
87,396 KB
testcase_18 AC 114 ms
78,040 KB
testcase_19 AC 102 ms
76,916 KB
testcase_20 AC 125 ms
78,016 KB
testcase_21 AC 131 ms
79,000 KB
testcase_22 AC 403 ms
90,308 KB
testcase_23 AC 1,459 ms
122,216 KB
testcase_24 AC 1,305 ms
120,836 KB
testcase_25 AC 1,604 ms
129,632 KB
testcase_26 AC 1,181 ms
115,176 KB
testcase_27 AC 1,336 ms
115,380 KB
testcase_28 AC 155 ms
82,316 KB
testcase_29 AC 1,487 ms
119,052 KB
testcase_30 AC 187 ms
89,168 KB
testcase_31 AC 184 ms
89,208 KB
testcase_32 AC 1,297 ms
120,268 KB
testcase_33 AC 349 ms
93,724 KB
testcase_34 AC 193 ms
89,396 KB
testcase_35 AC 344 ms
92,788 KB
testcase_36 AC 89 ms
71,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

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


ans = min(v[-2] for v in dp)
print(ans if ans < INF else -1)
# print(*dp, sep="\n")
0