結果
| 問題 |
No.2328 Build Walls
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-05-28 15:44:21 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 721 bytes |
| コンパイル時間 | 245 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 61,056 KB |
| 最終ジャッジ日時 | 2024-12-27 08:24:44 |
| 合計ジャッジ時間 | 21,610 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 WA * 15 TLE * 1 |
ソースコード
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H - 2)]
d = [[float('inf')] * W for _ in range(H - 2)]
for h in range(H - 2):
if A[h][0] == -1:
continue
d[h][0] = A[h][0]
for w in range(W - 1):
for h in range(H - 2):
if d[h][w] == float('inf'):
continue
for d_h in (-1, 0, 1):
if h + d_h < 0 or h + d_h >= H - 2:
continue
if A[h + d_h][w + 1] == -1:
continue
d[h + d_h][w + 1] = min(d[h + d_h][w + 1], d[h][w] + A[h + d_h][w + 1])
ans = float('inf')
for h in range(H - 2):
ans = min(ans, d[h][W - 1])
if ans == float('inf'):
print(-1)
else:
print(ans)