結果

問題 No.275 中央値を求めよ
ユーザー KotRm
提出日時 2019-03-15 11:43:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 542 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 68,884 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-28 17:07:48
合計ジャッジ時間 2,091 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define print(x) cout << x << endl;
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    
    int d;
    float ans;
    if(N%2==0){
        d = N/2;
        ans = (A[d]+A[d-1])/2.0;
    }else{
        d = N/2;
        ans = A[d];
    }
    print(ans);
    return 0;
}
0