結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー penguinshunya
提出日時 2017-12-31 19:10:59
言語 Rust
(1.93.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 1 ms / 1,000 ms
コード長 591 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,091 ms
コンパイル使用メモリ 200,404 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-11 05:22:04
合計ジャッジ時間 2,019 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fn main() {
    let _ = read::<u32>();
    let mut a = read_vec::<i32>();
    a.sort();
    let a:Vec<f64> = a.into_iter().map(|n|n as f64).collect();
    if a.len() % 2 == 1 {
        println!("{}", a[a.len()/2]);
    } else {
        println!("{}", (a[a.len()/2]+a[a.len()/2-1])/2f64);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
0