結果

問題 No.275 中央値を求めよ
ユーザー mnm
提出日時 2022-05-25 22:44:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 513 bytes
コンパイル時間 775 ms
コンパイル使用メモリ 79,172 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-20 14:49:42
合計ジャッジ時間 1,911 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i,n) for(i=0; i<n; ++i)
#define in(a) cin >> a
#define out(a,b) cout << a << b
using namespace std;
using lint = long long;

int main(void){
    int i, j, n, m, k, cnt = 0;
    float med;
    in(n);
    vector<int> A(n);
    rep(i,n)    in(A[i]);
    sort(A.begin(), A.end());
    if(n%2==0){
        med = (A[n/2]+A[n/2-1])/2.0;
        out(med,endl);
    }
    else    out(A[n/2],endl);

    return 0;
}
0