結果

問題 No.2095 High Rise
ユーザー phsplsphspls
提出日時 2022-10-23 12:43:23
言語 Rust
(1.77.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 921 ms
コンパイル使用メモリ 144,624 KB
実行使用メモリ 19,088 KB
最終ジャッジ日時 2023-09-14 23:41:35
合計ジャッジ時間 3,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 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,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 8 ms
4,376 KB
testcase_18 AC 6 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 9 ms
4,552 KB
testcase_21 AC 16 ms
5,984 KB
testcase_22 AC 62 ms
19,088 KB
testcase_23 AC 63 ms
18,860 KB
testcase_24 AC 63 ms
18,952 KB
testcase_25 AC 63 ms
19,040 KB
testcase_26 AC 62 ms
19,020 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 mut dp = vec![vec![INF; m]; n+1];
    for i in 0..m { dp[0][i] = 0; }
    for i in 0..n {
        let minval = (0..m).map(|j| dp[i][j]).min().unwrap();
        for j in 0..m {
            dp[i+1][j] = dp[i+1][j].min(dp[i][j] + rooms[i+1][j]);
            dp[i+1][j] = dp[i+1][j].min(minval + rooms[i][j] + rooms[i+1][j]);
        }
    }
    println!("{}", dp[n].iter().min().unwrap());
}
0