結果
| 問題 |
No.275 中央値を求めよ
|
| ユーザー |
|
| 提出日時 | 2025-09-22 11:37:19 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 1,000 ms |
| コード長 | 1,079 bytes |
| コンパイル時間 | 2,647 ms |
| コンパイル使用メモリ | 279,196 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-09-22 11:37:25 |
| 合計ジャッジ時間 | 4,438 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#include <bits/stdc++.h>
[[nodiscard]] static inline constexpr std::vector<int_least32_t> prepare(const uint_fast32_t N, const std::vector<int_least32_t>& A) noexcept
{
std::array<uint_least32_t, 2001> count_of = { 0, };
for (uint_fast32_t i = 0; i != N; ++i)
{
[[assume(A[i] >= -1000 && A[i] <= 1000)]];
++count_of[A[i] + 1000];
}
std::vector<int_least32_t> _A(N, 0);
for (int_fast32_t i = 0, j = 0; i != 2001; ++i)
while (count_of[i] != 0)
_A[j] = i - 1000, --count_of[i], ++j;
return _A;
}
[[nodiscard]] static inline constexpr double solve(const uint_fast32_t N, const std::vector<int_least32_t>& _A) noexcept
{
[[assume(std::is_sorted(_A.begin(), _A.end()))]];
if (N & 1) return _A[N / 2];
else return (_A[N / 2 - 1] + _A[N / 2]) / 2.0;
}
int main()
{
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
uint_fast32_t N;
std::cin >> N;
std::vector<int_least32_t> A(N);
for (uint_fast32_t i = 0; i != N; ++i)
std::cin >> A[i];
std::cout << std::fixed << std::setprecision(10) << solve(N, prepare(N, std::move(A))) << '\n';
return 0;
}