結果

問題 No.275 中央値を求めよ
ユーザー SAIKI_R_A
提出日時 2019-07-11 17:50:51
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 373 bytes
コンパイル時間 743 ms
コンパイル使用メモリ 74,368 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-08 00:26:34
合計ジャッジ時間 1,789 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main(void)
{
    int n;
    cin>>n;
    vector<int> k(n);
    
    for(int i=0;i<n;i++)
    {
        cin>>k[i];
    }
    
    sort(k.begin(),k.end());
    
    if(n%2==1)
    {
        cout<<k[n/2];
    }
    else
    {
        cout<<(double)(k[n/2-1]+k[n/2])/2.0;
    }
    cout<<endl;
}
0