結果
| 問題 |
No.2328 Build Walls
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-06-10 00:20:52 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 906 bytes |
| コンパイル時間 | 20,474 ms |
| コンパイル使用メモリ | 386,108 KB |
| 実行使用メモリ | 9,344 KB |
| 最終ジャッジ日時 | 2025-01-02 06:50:44 |
| 合計ジャッジ時間 | 17,804 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 22 RE * 3 |
ソースコード
use proconio::input;
use std::cmp::min;
const INF: isize = 1000000000000000000;
fn main() {
input!{
h: usize,
w: usize
}
let mut dp = vec![vec![INF; w]; h-2];
for i in 0..h-2 {
for j in 0..w {
input!{
a: isize
}
if a != -1 {
dp[i][j] = a;
}
}
}
for j in 1..w {
for i in 0..h-2 {
if i == 0 {
dp[i][j] += min(dp[i][j-1], dp[i+1][j-1]);
} else if i == h-3 {
dp[i][j] += min(dp[i-1][j-1], dp[i][j-1]);
} else {
dp[i][j] += min(dp[i][j-1], dp[i-1][j-1].min(dp[i+1][j-1]));
}
}
}
let mut ans = INF;
for i in 0..h-2 {
ans = ans.min(dp[i][w-1]);
}
if ans == INF {
println!("-1");
} else {
println!("{}", ans);
}
}