結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2021-07-18 23:58:13 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 21 ms / 1,000 ms |
コード長 | 452 bytes |
コンパイル時間 | 1,715 ms |
コンパイル使用メモリ | 198,168 KB |
最終ジャッジ日時 | 2025-01-23 03:16:18 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(void) { cin.tie(0); ios::sync_with_stdio(false); int n, t; vector <int> v; cin >> n; for (int i = 0; i < n; i++) { cin >> t; v.push_back(t); } sort(v.begin(), v.end()); if (n % 2 == 1) { cout << v[n / 2] << '\n'; } else { int sum = v[(n / 2) - 1] + v[(n / 2)]; double res = (sum / 2.0); cout << fixed; cout.precision(2); cout << res << '\n'; } return 0; }