結果

問題 No.275 中央値を求めよ
ユーザー _yoshih_
提出日時 2018-09-19 21:03:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 569 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 75,516 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-06-25 01:57:15
合計ジャッジ時間 1,721 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

static void setup()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
}

static void run()
{
    int n;
    cin >> n;

    vector<int> as;
    as.resize(n);
    for (auto i = 0; i < n; ++i) {
        cin >> as[i];
    }

    sort(begin(as), end(as));
    if (n % 2 == 0) {
        cout << (as[n / 2 - 1] + as[n / 2]) / 2.0f << endl;
    }
    else {
        cout << as[n / 2] << endl;
    }
}

int main(int argc, char **argv)
{
    setup();
    run();
    return 0;
}
0