結果
問題 | No.275 中央値を求めよ |
ユーザー | Sarievo |
提出日時 | 2023-05-23 16:05:00 |
言語 | Rust (1.77.0 + proconio) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,193 bytes |
コンパイル時間 | 13,788 ms |
コンパイル使用メモリ | 377,828 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-23 03:28:23 |
合計ジャッジ時間 | 15,499 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | WA | - |
testcase_06 | AC | 1 ms
5,248 KB |
testcase_07 | AC | 1 ms
5,248 KB |
testcase_08 | AC | 1 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | WA | - |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 1 ms
5,248 KB |
testcase_15 | WA | - |
testcase_16 | AC | 1 ms
5,248 KB |
testcase_17 | AC | 1 ms
5,248 KB |
testcase_18 | WA | - |
testcase_19 | AC | 1 ms
5,248 KB |
testcase_20 | AC | 1 ms
5,248 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 1 ms
5,248 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 1 ms
5,248 KB |
testcase_27 | AC | 1 ms
5,248 KB |
testcase_28 | AC | 1 ms
5,248 KB |
testcase_29 | AC | 1 ms
5,248 KB |
testcase_30 | AC | 1 ms
5,248 KB |
testcase_31 | AC | 1 ms
5,248 KB |
testcase_32 | AC | 1 ms
5,248 KB |
testcase_33 | AC | 1 ms
5,248 KB |
testcase_34 | AC | 1 ms
5,248 KB |
testcase_35 | AC | 1 ms
5,248 KB |
testcase_36 | AC | 1 ms
5,248 KB |
testcase_37 | AC | 1 ms
5,248 KB |
testcase_38 | AC | 1 ms
5,248 KB |
testcase_39 | AC | 1 ms
5,248 KB |
testcase_40 | AC | 1 ms
5,248 KB |
コンパイルメッセージ
warning: unused import: `std::collections::HashSet` --> src/main.rs:1:5 | 1 | use std::collections::HashSet; | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default warning: unused macro definition: `map` --> src/main.rs:5:14 | 5 | macro_rules! map { () => { ::std::collections::HashMap::new() }; ($($key: expr => $value: expr),+ $(,)?) => {{ const CAP: usize = $crate:... | ^^^ | = note: `#[warn(unused_macros)]` on by default warning: unused macro definition: `set` --> src/main.rs:6:14 | 6 | macro_rules! set { () => { ::std::collections::HashSet::new() }; ($($elem: expr),+ $(,)?) => {{ const CAP: usize = $crate::count!($($elem... | ^^^ warning: unused macro definition: `btmap` --> src/main.rs:7:14 | 7 | macro_rules! btmap { () => { ::std::collections::BTreeMap::new() }; ($($key: expr => $value: expr),+ $(,)?) => {{ let mut map = ::std::co... | ^^^^^ warning: unused macro definition: `btset` --> src/main.rs:8:14 | 8 | macro_rules! btset { () => { ::std::collections::BTreeSet::new() }; ($($elem: expr),+ $(,)?) => {{ let mut set = ::std::collections::BTre... | ^^^^^ warning: unused macro definition: `deque` --> src/main.rs:9:14 | 9 | macro_rules! deque { () => { ::std::collections::VecDeque::new() }; ($elem: expr; $n: expr) => {{ let mut deque = ::std::collections::Vec... | ^^^^^ warning: unused macro definition: `bheap` --> src/main.rs:10:14 | 10 | macro_rules! bheap { () => { ::std::collections::BinaryHeap::new() }; ($($elem: expr),+ $(,)?) => {{ const CAP: usize = $crate::count!($(... | ^^^^^ warning: unused macro definition: `cvec` --> src/main.rs:19:14 | 19 | macro_rules! cvec { ($($tokens: tt)+) => { $crate::c![$($tokens)+].collect::<::std::vec::Vec<_>>() }; } | ^^^^ warning: unused macro definition: `cmap` --> src/main.rs:20:14 | 20 | macro_rules! cmap { ($key:expr => $value:expr; $(
ソースコード
use std::collections::HashSet; // Copyright (c) 2023 Sarievo // https://github.com/GrayJack/sugars/blob/dev/LICENSE #[macro_export] macro_rules! count { (@subst $($x: tt)*) => (()); ($($rest: expr),*) => (<[()]>::len(&[$($crate::count!(@subst $rest)),*])); } macro_rules! map { () => { ::std::collections::HashMap::new() }; ($($key: expr => $value: expr),+ $(,)?) => {{ const CAP: usize = $crate::count!($($key),*); let mut map = ::std::collections::HashMap::with_capacity(CAP); $(let _ = map.insert($key, $value);)+map }}; } macro_rules! set { () => { ::std::collections::HashSet::new() }; ($($elem: expr),+ $(,)?) => {{ const CAP: usize = $crate::count!($($elem),*); let mut set = ::std::collections::HashSet::with_capacity(CAP); $(let _ = set.insert($elem);)+set }}; } macro_rules! btmap { () => { ::std::collections::BTreeMap::new() }; ($($key: expr => $value: expr),+ $(,)?) => {{ let mut map = ::std::collections::BTreeMap::new(); $(let _ = map.insert($key, $value);)+map }}; } macro_rules! btset { () => { ::std::collections::BTreeSet::new() }; ($($elem: expr),+ $(,)?) => {{ let mut set = ::std::collections::BTreeSet::new(); $(set.insert($elem);)+set }}; } macro_rules! deque { () => { ::std::collections::VecDeque::new() }; ($elem: expr; $n: expr) => {{ let mut deque = ::std::collections::VecDeque::new(); deque.resize_with($n, || $elem);deque }}; ($($elem: expr),+ $(,)?) => {{ const CAP: usize = $crate::count!($($elem),*); let mut deque = ::std::collections::VecDeque::with_capacity(CAP); $(deque.push_back($elem);)+deque }}; } macro_rules! bheap { () => { ::std::collections::BinaryHeap::new() }; ($($elem: expr),+ $(,)?) => {{ const CAP: usize = $crate::count!($($elem),*); let mut bheap = ::std::collections::BinaryHeap::with_capacity(CAP); $(bheap.push($elem);)+bheap }} } #[macro_export] macro_rules! c { ($e:expr; $i:pat in $iter:expr) => { $iter.map(|$i| $e) }; ($e:expr; $i:pat in $iter:expr, if $cond:expr) => {{ $iter.filter(|$i| $cond).map(|$i| $e) }}; ($e:expr; $i1:pat in $iter1:expr, $i2:pat in $iter2:expr) => {{ $iter1.flat_map(|$i1| $iter2.map(move |$i2| $e)) }}; ($e:expr; $i1:pat in $iter1:expr, $i2:pat in $iter2:expr, if $cond:expr) => {{ $iter1.flat_map(|$i1| $iter2.filter_map(move |$i2| if $cond { Some($e) } else { None })) }}; ($e:expr; $i1:pat in $iter1:expr, $i2:pat in $iter2:expr, $i3:pat in $iter3:expr) => {{ $iter1.flat_map(|$i1| $iter2.flat_map(move |$i2| $iter3.map(move |$i3| $e))) }}; ($e:expr; $i1:pat in $iter1:expr, $i2:pat in $iter2:expr, $i3:pat in $iter3:expr, if $cond:expr) => {{ $iter1.flat_map(|$i1| { $iter2.flat_map(move |$i2| { $iter3.filter_map(move |$i3| if $cond { Some($e) } else { None }) }) }) }}; } macro_rules! cvec { ($($tokens: tt)+) => { $crate::c![$($tokens)+].collect::<::std::vec::Vec<_>>() }; } macro_rules! cmap { ($key:expr => $value:expr; $($tokens: tt)+) => {{ $crate::c![ ($key, $value); $($tokens)+ ].collect::<::std::collections::HashMap<_, _>>() }}; } macro_rules! cset { ($($tokens: tt)+) => {{ $crate::c![$($tokens)+].collect::<::std::collections::HashSet<_>>() }}; } macro_rules! cbtmap { ($key:expr => $value:expr; $($tokens: tt)+) => {{ $crate::c![ ($key, $value); $($tokens)+ ].collect::<::std::collections::BTreeMap<_, _>>() }}; } macro_rules! cbtset { ($($tokens: tt)+) => {{ $crate::c![$($tokens)+].collect::<::std::collections::BTreeSet<_>>() }}; } macro_rules! cdeque { ($($tokens: tt)+) => {{ use std::collections::VecDeque; $crate::c![$($tokens)+].collect::<::std::collections::VecDeque<_>>() }}; } macro_rules! cbheap { ($($tokens: tt)+) => {{ use std::collections::BinaryHeap; $crate::c![$($tokens)+].collect::<::std::collections::BinaryHeap<_>>() }}; } const DX: [i32; 8] = [0, 1, 0, -1, 1, 1, -1, -1]; const DY: [i32; 8] = [1, 0, -1, 0, 1, -1, -1, 1]; fn main() { let (r, w) = (std::io::stdin(), std::io::stdout()); let mut sc = IO::new(r.lock(), w.lock()); let n = sc.read(); let mut v: Vec<i64> = sc.vec(n); v.sort(); let mut ans = -1; if n & 1 == 1 { ans = v[n / 2]; } else { ans = (v[n / 2] + v[n / 2 - 1]) / 2; } println!("{}", ans); } pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>); impl<R: std::io::Read, W: std::io::Write> IO<R, W> { pub fn new(r: R, w: W) -> Self { Self(r, std::io::BufWriter::new(w)) } pub fn write<S: ToString>(&mut self, s: S) { use std::io::Write; self.1.write_all(s.to_string().as_bytes()).unwrap(); } pub fn read<T: std::str::FromStr>(&mut self) -> T { use std::io::Read; let buf = self.0.by_ref().bytes() .map(|b| b.unwrap()) .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t') .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t') .collect::<Vec<_>>(); unsafe { std::str::from_utf8_unchecked(&buf) }.parse().ok().expect("Parse error.") } pub fn chars(&mut self) -> Vec<char> { self.read::<String>().chars().collect() } pub fn usize0(&mut self) -> usize { self.read::<usize>() - 1 } pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.read()).collect() } }