結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2020-08-26 21:28:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 1,000 ms |
コード長 | 801 bytes |
コンパイル時間 | 1,111 ms |
コンパイル使用メモリ | 85,304 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-07 13:40:56 |
合計ジャッジ時間 | 2,359 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#define _USE_MATH_DEFINES#include <iostream> //cin, cout#include <vector> //vector#include <algorithm> //sort,min,max,count#include <string> //string#include <ios> //fixed#include <iomanip> //setprecision#include <utility> //swap#include <cstdlib> //abs(int)#include <cmath> //sqrt#include <sstream> //stringstream,getline#include <cmath> //ceil,M_PIusing namespace std;inline double Median(vector<int>& A) {int temp = A.size();sort(A.begin(), A.end());if (temp % 2 == 0) {double ans = (A[(temp / 2) - 1] + A[temp / 2]) / 2.0;return ans;}else {return A[temp / 2];}}int main() {int N;cin >> N;vector<int> A(N);for (int i = 0; i < N; i++) {cin >> A[i];}double ans = Median(A);cout << fixed << setprecision(15) << ans << endl;return 0;}