結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2018-04-01 21:08:25 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 609 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 31,232 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-25 01:08:56 |
合計ジャッジ時間 | 1,434 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#include<stdio.h> #include<stdlib.h> int main(void){ int n,i,j,l,r,p,t=2,x; int *a,*s; scanf("%d",&n); a=(int*)malloc(sizeof(int)*n); s=(int*)malloc(sizeof(int)*n); s[0]=0; s[1]=n-1; for(i=0;i<n;i++){ scanf("%d",&a[i]); } while(t>0){ t-=2; i=l=s[t]; j=r=s[t+1]; p=a[i]; while(i<=j){ while(a[i]<p&&i<r) i++; while(a[j]>=p&&j>l) j--; if(i<=j){ x=a[i]; a[i]=a[j]; a[j]=x; i++; j--; } } if(j>l){ s[t]=l; s[t+1]=j; t+=2; } if(r>i){ s[t]=i; s[t+1]=r; t+=2; } } printf("%g\n",(double)(a[(n-1)/2]+a[n/2])/2); return 0; }