結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
FF256grhy
|
| 提出日時 | 2015-09-04 22:36:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 520 bytes |
| コンパイル時間 | 98 ms |
| コンパイル使用メモリ | 23,424 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-19 01:02:18 |
| 合計ジャッジ時間 | 1,166 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 35 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:10:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
10 | scanf("%d", &temp);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int n, a[2001];
int main(void) {
scanf("%d", &n);
int i;
for(i = 0; i < n; i++) {
int temp;
scanf("%d", &temp);
a[temp + 1000]++;
}
int c = 0, flag = 0, ans = 0;
for(i = 0; i < 2001; i++) {
if(a[i]) {
c += a[i];
if(n % 2) {
if(c > n / 2) {
ans = 2 * (i - 1000);
break;
}
} else {
if(c >= n / 2) {
ans += i - 1000;
if( ! flag) {
flag = 1;
} else {
break;
}
}
}
}
}
printf("%f\n", ans / 2.0 );
return 0;
}
FF256grhy