結果

問題 No.275 中央値を求めよ
ユーザー iodo_shiba
提出日時 2018-08-30 08:24:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 409 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 64,972 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-25 01:55:58
合計ジャッジ時間 1,657 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>

int main(){
    int N;
    std::cin >> N;
    std::vector<int> x;
    for(int i=0;i<N;i++){
        int t;
        std::cin >> t;
        x.push_back(t);
    }
    std::sort(x.begin(),x.end());
    if(N%2==0){
        std::cout << static_cast<double>(x[N/2-1]+x[N/2])/2 <<std::endl;
    }
    else{
        std::cout << x[(N-1)/2] << std::endl;
    }
}
0