結果

問題 No.2095 High Rise
ユーザー phsplsphspls
提出日時 2022-11-06 14:55:00
言語 Rust
(1.77.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,042 bytes
コンパイル時間 3,136 ms
コンパイル使用メモリ 149,308 KB
実行使用メモリ 19,056 KB
最終ジャッジ日時 2023-09-27 10:12:48
合計ジャッジ時間 5,630 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 7 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 7 ms
4,468 KB
testcase_21 AC 13 ms
6,004 KB
testcase_22 AC 56 ms
19,056 KB
testcase_23 AC 58 ms
18,892 KB
testcase_24 AC 58 ms
18,940 KB
testcase_25 AC 58 ms
19,040 KB
testcase_26 AC 58 ms
18,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;

fn main() {
    let mut nm = String::new();
    std::io::stdin().read_line(&mut nm).ok();
    let nm: Vec<usize> = nm.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let n = nm[0];
    let m = nm[1];
    let mut rooms = (0..n).map(|_| {
            let mut temp = String::new();
            std::io::stdin().read_line(&mut temp).ok();
            let temp: Vec<usize> = temp.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();
            temp
        })
        .collect::<Vec<_>>();

    if n == 1 {
        println!("0");
        return;
    }
    rooms.insert(0, vec![0usize; m]);
    let n = n+1;
    let mut dp = vec![vec![INF; m]; n];
    dp[0] = vec![0usize; m];
    for i in 1..n {
        let minval = *dp[i-1].iter().min().unwrap();
        for j in 0..m {
            dp[i][j] = dp[i][j].min(dp[i-1][j] + rooms[i][j]);
            dp[i][j] = dp[i][j].min(minval + rooms[i][j] + rooms[i-1][j])
        }
    }
    println!("{}", dp[n-1].iter().min().unwrap());
}
0