結果

問題 No.275 中央値を求めよ
ユーザー Luna
提出日時 2018-05-09 11:41:56
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 465 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 72,096 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-28 02:39:15
合計ジャッジ時間 1,886 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28 WA * 10
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

int main(int argc, char const* argv[]) {
    int N;
    double ans;

    cin >> N;

    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

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

    if (N % 2 == 0) {
        ans = (A[N/2-1] + A[N/2]) / 2.0;
    } else {
        ans = A[N/2];
    }

    cout << setprecision(2) << ans << endl;
    return 0;
}
0