結果
| 問題 |
No.275 中央値を求めよ
|
| ユーザー |
|
| 提出日時 | 2021-07-13 00:04:09 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 379 bytes |
| コンパイル時間 | 635 ms |
| コンパイル使用メモリ | 78,180 KB |
| 最終ジャッジ日時 | 2025-01-23 00:51:11 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<double> d(n);
for (int i = 0; i < n; i++) {
cin >> d[i];
}
sort(d.begin(), d.end());
if (n % 2 == 0) {
cout << (d[n / 2] + d[n / 2 - 1]) / 2 << endl;
} else {
cout << d[n / 2] << endl;
}
return 0;
}