結果

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

ソースコード

diff #
raw source code

use std::io;

fn main() {
    let mut n = String::new();
    io::stdin().read_line(&mut n).unwrap();
    let n: usize = n.trim().parse().unwrap();

    let mut a = String::new();
    io::stdin().read_line(&mut a).unwrap();
    let mut a: Vec<i32> = a.trim()
        .split(' ')
        .take(n)
        .map(|s| s.parse().unwrap())
        .collect();
    a.sort();

    let median = match n % 2 {
        0 => (a[n / 2 - 1] + a[n / 2]) as f32 / 2.0,
        _ => a[n / 2] as f32,
    };

    println!("{}", median);
}
0