結果

問題 No.1077 Noelちゃんと星々4
コンテスト
ユーザー akakimidori
提出日時 2020-06-12 21:37:53
言語 Rust
(1.99.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 8 ms / 2,000 ms
+ 530µs
コード長 790 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 11,325 ms
コンパイル使用メモリ 189,784 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-11-04 19:54:24
合計ジャッジ時間 8,950 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: use of deprecated constant `std::i32::MAX`: replaced by the `MAX` associated constant on this type
  --> src/main.rs:15:39
   |
15 |         let mut next = vec![std::i32::MAX / 10; w + 1];
   |                                       ^^^
   |
   = note: `#[warn(deprecated)]` on by default

warning: use of deprecated constant `std::i32::MAX`: replaced by the `MAX` associated constant on this type
  --> src/main.rs:16:33
   |
16 |         let mut val = std::i32::MAX / 10;
   |                                 ^^^

ソースコード

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