結果

問題 No.1077 Noelちゃんと星々4
ユーザー phspls
提出日時 2023-01-05 02:23:53
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 12,779 ms
コンパイル使用メモリ 405,116 KB
実行使用メモリ 80,000 KB
最終ジャッジ日時 2024-11-28 12:24:31
合計ジャッジ時間 14,861 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;
const LIMIT: usize = 10000;

fn main() {
    let mut n = String::new();
    std::io::stdin().read_line(&mut n).ok();
    let n: usize = n.trim().parse().unwrap();
    let mut y = String::new();
    std::io::stdin().read_line(&mut y).ok();
    let y: Vec<usize> = y.trim().split_whitespace().map(|s| s.parse().unwrap()).collect();

    let mut dp = vec![vec![INF; LIMIT+1]; n];
    for j in 0..=LIMIT {
        dp[0][j] = y[0].max(j) - y[0].min(j);
    }
    for i in 1..n {
        let mut prevmin = INF;
        for j in 0..=LIMIT {
            prevmin = prevmin.min(dp[i-1][j]);
            let diff = y[i].max(j) - y[i].min(j);
            dp[i][j] = prevmin + diff;
        }
    }
    println!("{}", dp[n-1].iter().min().unwrap());
}
0