結果
| 問題 |
No.275 中央値を求めよ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-27 17:49:55 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,074 bytes |
| コンパイル時間 | 343 ms |
| コンパイル使用メモリ | 30,848 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-20 20:34:15 |
| 合計ジャッジ時間 | 2,411 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | AC * 6 WA * 30 RE * 2 |
ソースコード
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main ( void )
{
uint16_t n, i, n_half;
int16_t a[1000], sort_temp;
int16_t sort_min, sort_max;
uint16_t sort_min_index, sort_max_index;
uint16_t sorted = 0u;
scanf("%d", &n);
for ( i = 0u; i < n; i++ ) {
scanf("%d", &a[i]);
}
n_half = n / 2;
while ( sorted < n_half ) {
sort_min = 1000;
sort_max = -1000;
for ( i = sorted; i < n; i++ ) {
if ( sort_min > a[i] ) {
sort_min = a[i];
sort_min_index = i;
}
if ( sort_max < a[i] ) {
sort_max = a[i];
sort_max_index = i;
}
}
sort_temp = a[sort_min_index];
a[sort_min_index] = a[sorted];
a[sorted] = sort_temp;
sort_temp = a[sort_max_index];
a[sort_max_index] = a[n - 1 - sorted];
a[n - 1 - sorted] = sort_temp;
sorted ++;
}
for ( i = 0; i < n; i++ ) {
if ( i > 0 ) {
fprintf(stderr, ", ");
}
fprintf(stderr, "%d", a[i]);
}
fprintf(stderr, "\n");
if ( n % 2 ) {
printf("%d\n", a[n_half]);
} else {
printf("%.1f\n", ((float)a[n_half] + (float)a[n_half - 1]) / 2);
}
return 0;
}