結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2019-02-10 17:54:58 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 496 bytes |
コンパイル時間 | 1,934 ms |
コンパイル使用メモリ | 161,124 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-07-06 14:35:16 |
合計ジャッジ時間 | 2,839 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main() {// 1. 入力情報取得.int N;cin >> N;int A[N];for(int i = 0; i < N; i++) cin >> A[i];// 2. 中央値を計算.sort(A, A + N);int index = N / 2;double ans = 0.0;if(N % 2 == 1) ans = A[index];else ans = (A[index - 1] + A[index] + 0.0) / 2;// 3. 出力 ~ 後処理.cout << fixed;cout << setprecision(20) << ans << endl;return 0;}