結果

問題 No.275 中央値を求めよ
ユーザー alchemin
提出日時 2019-09-14 21:02:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 505 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 75,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-06 13:39:09
合計ジャッジ時間 1,941 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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 ;
    
    int tmp;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(v.begin(), v.end());
    
    int i;
    double ans;
    if (n % 2 == 0) {
        i = (n / 2) - 1;
        ans = (v[i] + v[i + 1]) / 2.0;
    } else {
        i = n / 2;
        ans = v[i];
    }
    
    cout << ans << endl;
    
    return 0;
}
0