結果

問題 No.1077 Noelちゃんと星々4
ユーザー phsplsphspls
提出日時 2023-01-05 02:23:53
言語 Rust
(1.77.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 5,987 ms
コンパイル使用メモリ 140,848 KB
実行使用メモリ 80,076 KB
最終ジャッジ日時 2023-08-19 00:23:10
合計ジャッジ時間 2,932 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 48 ms
55,456 KB
testcase_03 AC 61 ms
71,368 KB
testcase_04 AC 17 ms
22,784 KB
testcase_05 AC 14 ms
17,488 KB
testcase_06 AC 23 ms
28,848 KB
testcase_07 AC 27 ms
33,064 KB
testcase_08 AC 19 ms
24,628 KB
testcase_09 AC 16 ms
21,464 KB
testcase_10 AC 60 ms
71,296 KB
testcase_11 AC 38 ms
46,732 KB
testcase_12 AC 32 ms
38,872 KB
testcase_13 AC 13 ms
16,720 KB
testcase_14 AC 58 ms
69,736 KB
testcase_15 AC 31 ms
37,528 KB
testcase_16 AC 19 ms
25,160 KB
testcase_17 AC 35 ms
42,320 KB
testcase_18 AC 62 ms
72,616 KB
testcase_19 AC 12 ms
15,924 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 68 ms
80,076 KB
権限があれば一括ダウンロードができます

ソースコード

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