結果

問題 No.77 レンガのピラミッド
ユーザー tonyu0
提出日時 2020-03-29 00:34:36
言語 Rust
(1.83.0 + proconio)
結果
RE  
実行時間 -
コード長 1,053 bytes
コンパイル時間 13,230 ms
コンパイル使用メモリ 388,112 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2025-01-02 12:30:46
合計ジャッジ時間 12,650 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 2 WA * 12 RE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let a: Vec<i32> = (0..n)
        .map(|_| itr.next().unwrap().parse().unwrap())
        .collect();

    let mut ans = 1 << 30;
    let center = n / 2;
    for i in 1..(n / 2 + 2) as i32 {
        let mut diff = a[center] - i;
        let mut cnt = diff.abs();
        for j in 1..n / 2 + 1 {
            let need = i - j as i32;
            if need <= 0 {
                diff += a[center + j] + a[center - j];
                cnt += a[center + j] + a[center - j];
                continue;
            }
            diff += a[center + j] - need;
            diff += a[center - j] - need;
            cnt += (a[center + j] - need).abs();
            cnt += (a[center - j] - need).abs();
        }
        if diff >= 0 {
            ans = std::cmp::min(ans, (cnt - diff) / 2 + diff);
        }
    }
    println!("{}", ans);
}
0