結果

問題 No.1077 Noelちゃんと星々4
ユーザー phsplsphspls
提出日時 2023-01-11 23:39:24
言語 Rust
(1.77.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 781 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 145,508 KB
実行使用メモリ 80,056 KB
最終ジャッジ日時 2023-08-24 04:13:13
合計ジャッジ時間 3,447 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 60 ms
55,500 KB
testcase_03 AC 72 ms
71,312 KB
testcase_04 AC 22 ms
22,736 KB
testcase_05 AC 17 ms
17,496 KB
testcase_06 AC 29 ms
28,860 KB
testcase_07 AC 33 ms
33,060 KB
testcase_08 AC 25 ms
24,612 KB
testcase_09 AC 22 ms
21,436 KB
testcase_10 AC 73 ms
71,328 KB
testcase_11 AC 47 ms
46,756 KB
testcase_12 AC 39 ms
38,840 KB
testcase_13 AC 16 ms
16,716 KB
testcase_14 AC 71 ms
69,764 KB
testcase_15 AC 37 ms
37,580 KB
testcase_16 AC 26 ms
25,160 KB
testcase_17 AC 43 ms
42,316 KB
testcase_18 AC 74 ms
72,668 KB
testcase_19 AC 15 ms
15,840 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 82 ms
80,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const INF: usize = 1usize << 60;
const LIMIT: usize = 1e4 as usize;

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 i in 0..=LIMIT {
        dp[0][i] = y[0].max(i) - y[0].min(i);
    }
    for i in 1..n {
        let mut pmin = INF;
        for j in 0..=LIMIT {
            pmin = pmin.min(dp[i-1][j]);
            let diff = y[i].max(j) - y[i].min(j);
            dp[i][j] = dp[i][j].min(pmin + diff);
        }
    }
    println!("{}", dp[n-1].iter().min().unwrap());
}
0