結果
問題 | No.2328 Build Walls |
ユーザー |
|
提出日時 | 2023-06-10 00:36:42 |
言語 | Rust (1.83.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,505 bytes |
コンパイル時間 | 12,440 ms |
コンパイル使用メモリ | 402,636 KB |
実行使用メモリ | 7,040 KB |
最終ジャッジ日時 | 2025-01-02 07:12:55 |
合計ジャッジ時間 | 14,791 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 WA * 15 |
ソースコード
use std::cmp::min;const INF: isize = 1000000000000000000;fn main() {let (h, w): (usize, usize) = {let mut line: String = String::new();std::io::stdin().read_line(&mut line).unwrap();let mut iter = line.split_whitespace();(iter.next().unwrap().parse().unwrap(),iter.next().unwrap().parse().unwrap())};let mut dp = vec![vec![INF; w]; h-2];for i in 0..h-2 {let a: Vec<isize> = {let mut line: String = String::new();std::io::stdin().read_line(&mut line).unwrap();line.split_whitespace().map(|x| x.parse().unwrap()).collect()};for j in 0..w {if a[j] != -1 {dp[i][j] = a[j];}}}for j in 1..w {for i in 0..h-2 {if dp[i][j] != INF {if h == 3 {dp[i][j] += dp[i][j-1];} else 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);}}