結果

問題 No.3016 ハチマキおじさん
ユーザー magurofly
提出日時 2025-01-25 14:12:46
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 60 ms / 2,000 ms
コード長 1,020 bytes
コンパイル時間 13,771 ms
コンパイル使用メモリ 406,504 KB
実行使用メモリ 17,616 KB
最終ジャッジ日時 2025-01-25 23:11:09
合計ジャッジ時間 16,252 ms
ジャッジサーバーID
(参考情報)
judge10 / judge6
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: unused import: `proconio::marker::Chars`
 --> src/main.rs:6:5
  |
6 | use proconio::marker::Chars;
  |     ^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

ソースコード

diff #

#![allow(non_snake_case)]

use std::collections::HashSet;

use proconio::input;
use proconio::marker::Chars;

const INF: i64 = 1_000_000_000_000_000_000;

fn main() {
    input! {
        N: usize,
        mut A: [i64; N],
        mut B: [i64; N - 1],
    }

    A.sort();
    B.sort();

    let mut left = vec![0; N];
    let mut right = vec![0; N];
    for i in 0 .. N - 1 {
        left[i + 1] = left[i] + (A[i] - B[i]).abs();
        right[i + 1] = right[i] + (A[i + 1] - B[i]).abs();
    }

    let mut ans_set = HashSet::new();
    let mut ans_value = INF;
    for i in 0 .. N {
        let cost = left[i] - left[0] + right[N - 1] - right[i];
        if ans_value > cost {
            ans_value = cost;
            ans_set.clear();
        }
        if ans_value == cost {
            ans_set.insert(A[i]);
        }
    }

    let mut ans = ans_set.into_iter().collect::<Vec<_>>();
    ans.sort();

    println!("{}", ans.len());
    println!("{}", ans.iter().map(i64::to_string).collect::<Vec<_>>().join(" "));
}
0