結果

問題 No.275 中央値を求めよ
ユーザー t-0ga
提出日時 2019-07-10 11:40:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 268 bytes
コンパイル時間 1,260 ms
コンパイル使用メモリ 159,960 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-14 17:14:10
合計ジャッジ時間 2,342 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() 
{
  int n;
  cin >> n;
  int a[1000];
  for (auto& i : a) cin >> i;
  sort(a, a + n);
  if (n & 1) 
  {
    cout << a[n / 2] << endl;
  } 
  else 
  {
    cout << (a[n / 2 - 1] + a[n / 2]) / 2.0 << endl;
  }
}
0