結果
| 問題 | No.275 中央値を求めよ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-24 01:46:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 記録 | |
| 実行時間 | - |
| コード長 | 1,010 bytes |
| コンパイル時間 | 1,695 ms |
| コンパイル使用メモリ | 172,872 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 01:44:33 |
| 合計ジャッジ時間 | 3,422 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 4 WA * 34 |
ソースコード
/**
* author: ekusiadadus
* created: 18.08.2021 13:43:33
**/
// #include<bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
map < int, long long > m;
double get_median() {
if (m.size() % 2 == 0) {
int cnt = 0;
double ans = 0;
for (auto it: m) {
if (cnt == m.size() / 2 - 1) ans += it.first;
if (cnt == m.size() / 2) ans += it.first;
cnt++;
}
return ans / 2.0;
}
int cnt = 0;
double ans = 0;
for (auto it: m) {
cnt++;
if (cnt == m.size() / 2) ans = it.first;
}
return ans;
}
int main() {
// ifstream in ("input.txt");
// if (! in ) {
// cerr << "Error" << endl;
// return 0;
// }
// string str;
// int x;
// while (getline( in , str)) {
// stringstream stream(str);
// while (1) {
// stream >> x;
// if (!stream) break;
// m[x]++;
// }
// }
int n;
cin >> n;
for(int i = 0; i < n; ++i){
int x;
cin >> x;
m[x]++;
}
cout << get_median() << endl;
return 0;
}