結果

問題 No.3632 IQR
コンテスト
ユーザー norioc
提出日時 2026-08-24 02:07:33
言語 Rust
(1.94.0 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 35 ms / 2,000 ms
+ 910µs
コード長 1,163 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,091 ms
コンパイル使用メモリ 191,704 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-08-24 02:07:39
合計ジャッジ時間 5,266 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 63
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![allow(non_snake_case, unused_imports)]

use std::collections::{BinaryHeap, HashMap, HashSet};
use proconio::{input, marker::Usize1, marker::Chars};
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! d {
    ( $( $x:expr ),* $(,)? ) => {
        eprintln!(
            concat!( $( stringify!($x), "={:?} " ),* ),
            $( $x ),*
        );
    };
}

#[allow(dead_code)]
fn yn(b: bool) -> &'static str {
    if b { "Yes" } else { "No" }
}


fn median(a: &[f64]) -> f64 {
    if a.len() % 2 == 1 {
        a[a.len() / 2]
    } else {
        let s = a.len() / 2;
        (a[s-1] + a[s]) / 2.0
    }
}

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

    let v = A.iter()
        .sorted()
        .map(|&x| x as f64)
        .collect_vec();

    let k = N / 2;
    let q1 = median(&v[..k]);
    let q2 = median(&v);
    let q3 = median(&v[v.len()-k..]);

    let iqr = q3 - q1;
    let cnt = v.iter()
        .filter(|&&x| {
            if x < q1 - 1.5 * iqr { return true }
            if x > q3 + 1.5 * iqr { return true }
            false
        })
        .count();

    println!("{} {} {} {}", q1, q2, q3, cnt);
}
0