結果

問題 No.275 中央値を求めよ
ユーザー Rittai_3D
提出日時 2016-10-06 15:21:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 655 bytes
コンパイル時間 2,024 ms
コンパイル使用メモリ 170,888 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-25 00:04:23
合計ジャッジ時間 2,662 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using pint = pair< int, int >;
using ull = unsigned long long;

template< typename T >
void output( T&& range )
{
    for_each(
        begin( range ),
        end( range ),
        []( auto&& t )
        {
            cerr << t << endl;
        }
    );
}


int main()
{
    int n = 0;
    cin >> n;
    
    vector< int > v( n );
    
    for( auto&& i : v ) {
        cin >> i;
    }
    
    sort( begin( v ), end( v ) );
    
    if( n % 2 == 0 ) {
        cout << ( v[ ( n / 2 ) ] + v[ ( n / 2 ) - 1 ] ) / 2.0 << endl;
        return 0;
    }
    else {
        cout << v[ ( n / 2 ) ] << endl;
    }
}
0