結果

問題 No.2328 Build Walls
ユーザー so-heyso-hey
提出日時 2023-06-10 00:28:14
言語 Rust
(1.77.0)
結果
RE  
実行時間 -
コード長 1,351 bytes
コンパイル時間 2,947 ms
コンパイル使用メモリ 139,908 KB
実行使用メモリ 7,076 KB
最終ジャッジ日時 2023-08-30 15:28:37
合計ジャッジ時間 5,979 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 RE -
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 1 ms
4,376 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 29 ms
7,044 KB
testcase_34 WA -
testcase_35 AC 31 ms
7,012 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 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);
    }
}
0