結果

問題 No.275 中央値を求めよ
ユーザー h_noson
提出日時 2015-12-23 17:03:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 397 bytes
コンパイル時間 579 ms
コンパイル使用メモリ 66,536 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-24 23:35:43
合計ジャッジ時間 1,621 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "vector"
#include "algorithm"
using namespace std;

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