結果

問題 No.275 中央値を求めよ
ユーザー marinebox
提出日時 2020-11-13 04:35:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 340 bytes
コンパイル時間 1,650 ms
コンパイル使用メモリ 171,844 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-22 19:51:49
合計ジャッジ時間 2,899 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    for(auto &i : a) cin >> i;

    sort(a.begin(), a.end());

    double ans;
    if(n % 2 != 0){
        ans = a[n / 2];
    }
    else{
        ans = (a[n / 2 - 1] + a[n / 2]) / 2;
    }

    cout << ans << endl;
    return 0;
}
0