結果
問題 |
No.275 中央値を求めよ
|
ユーザー |
|
提出日時 | 2016-02-18 08:19:43 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 630 bytes |
コンパイル時間 | 534 ms |
コンパイル使用メモリ | 66,492 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 23:42:26 |
合計ジャッジ時間 | 1,593 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <iterator> int main(){ int N; std::vector<int> A; std::cin >> N; A.reserve(N); std::copy_n(std::istream_iterator<int>(std::cin),N,std::back_inserter(A)); if(N%2){ // odd auto center = (N>>1) + 1; std::nth_element(A.begin(),A.begin()+center-1,A.end()); std::cout << A[center-1] << std::endl; }else{ // even auto center_min = (N>>1); std::nth_element(A.begin(),A.begin()+center_min-1,A.end()); std::cout << (A[center_min-1] + (* std::min_element(A.begin()+center_min,A.end())))/2.0 << std::endl; } return 0; }