結果

問題 No.1077 Noelちゃんと星々4
コンテスト
ユーザー akakimidori
提出日時 2020-06-12 21:37:53
言語 Rust
(1.93.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 790 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,218 ms
コンパイル使用メモリ 196,644 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-10 02:55:24
合計ジャッジ時間 2,301 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let _n: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<i32> = it.map(|s| s.parse().unwrap()).collect();
    let w = 10000;
    let mut dp = vec![0i32; w + 1];
    for i in 0..=w {
        dp[i] = (i as i32 - a[0]).abs();
    }
    for &a in a.iter().skip(1) {
        let mut next = vec![std::i32::MAX / 10; w + 1];
        let mut val = std::i32::MAX / 10;
        for i in 0..=w {
            val = std::cmp::min(val, dp[i]);
            next[i] = val + (a - i as i32).abs();
        }
        dp = next;
    }
    let ans = dp.into_iter().min().unwrap();
    println!("{}", ans);
}

fn main() {
    run();
}
0