結果

問題 No.275 中央値を求めよ
ユーザー brave_reverse_brave_reverse_
提出日時 2016-01-08 15:19:22
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,080 bytes
コンパイル時間 3,414 ms
コンパイル使用メモリ 77,728 KB
実行使用メモリ 60,152 KB
最終ジャッジ日時 2023-10-19 16:48:00
合計ジャッジ時間 11,751 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 145 ms
57,388 KB
testcase_03 AC 131 ms
57,468 KB
testcase_04 AC 132 ms
57,500 KB
testcase_05 AC 131 ms
57,504 KB
testcase_06 AC 142 ms
57,596 KB
testcase_07 AC 197 ms
57,812 KB
testcase_08 AC 150 ms
57,556 KB
testcase_09 AC 149 ms
57,456 KB
testcase_10 AC 150 ms
57,744 KB
testcase_11 WA -
testcase_12 AC 128 ms
57,088 KB
testcase_13 AC 129 ms
57,404 KB
testcase_14 AC 133 ms
57,488 KB
testcase_15 AC 214 ms
59,860 KB
testcase_16 AC 207 ms
59,984 KB
testcase_17 AC 200 ms
59,640 KB
testcase_18 AC 164 ms
57,444 KB
testcase_19 AC 200 ms
57,840 KB
testcase_20 AC 206 ms
60,152 KB
testcase_21 AC 189 ms
57,796 KB
testcase_22 AC 206 ms
59,788 KB
testcase_23 AC 184 ms
57,712 KB
testcase_24 AC 169 ms
57,796 KB
testcase_25 AC 210 ms
59,964 KB
testcase_26 AC 214 ms
59,992 KB
testcase_27 AC 205 ms
57,712 KB
testcase_28 AC 142 ms
57,664 KB
testcase_29 AC 166 ms
57,684 KB
testcase_30 AC 144 ms
57,800 KB
testcase_31 AC 206 ms
60,056 KB
testcase_32 AC 150 ms
57,652 KB
testcase_33 AC 203 ms
60,008 KB
testcase_34 AC 143 ms
57,692 KB
testcase_35 AC 207 ms
57,728 KB
testcase_36 AC 189 ms
57,740 KB
testcase_37 AC 151 ms
55,616 KB
testcase_38 AC 157 ms
57,700 KB
testcase_39 AC 158 ms
57,824 KB
testcase_40 AC 213 ms
60,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicorder;
import java.util.Scanner;

public class QNo275 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		short n = sc.nextShort();
		short[] a = new short[n+1];
		short[] out = new short[n+1];
		a[0] = -10000;
		out[0] = -10000;
		for(int i=1;i<=n;i++){
			a[i] = sc.nextShort();
		}
		for(short i =n;i>0;i--){
			partHeap(i,a);
		}
		for(short k=n;k>1;k--){
			out[k] = a[1];
			a[1] = a[k];
			a[k] = -10000;
			partHeap((short)1,a);
		}
		
	    double center = -10000;
	    if(n%2==0) center = (double)(out[n/2] + out[n/2+1])/2;
	    else center = out[n/2+1];
	    System.out.println(center);
		
	}
	
	private static void partHeap(short parent,short[] a){
		short cand = -10000;
		short lr = -1;
		short pare = -10000;
		try{
			pare = a[parent];
			cand = a[parent*2];
			lr = 0;
			if(cand<a[parent*2+1]){
				cand = a[parent*2+1];
				lr = 1;
			}	
		}catch(IndexOutOfBoundsException e){
			if(lr==-1) return;
		}
		if(cand > pare){
			a[parent] = cand;
			a[parent*2+lr] = pare;
			partHeap((short)(parent*2+lr),a);
		}
	}
}
0