結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 131 ms
57,432 KB
testcase_04 AC 121 ms
56,188 KB
testcase_05 WA -
testcase_06 AC 145 ms
57,508 KB
testcase_07 AC 195 ms
57,668 KB
testcase_08 AC 151 ms
57,688 KB
testcase_09 AC 152 ms
57,708 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 132 ms
57,452 KB
testcase_13 AC 133 ms
57,352 KB
testcase_14 AC 128 ms
57,384 KB
testcase_15 WA -
testcase_16 AC 206 ms
59,888 KB
testcase_17 AC 208 ms
59,972 KB
testcase_18 WA -
testcase_19 AC 202 ms
57,656 KB
testcase_20 AC 202 ms
57,688 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 190 ms
58,096 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 207 ms
59,844 KB
testcase_27 AC 204 ms
57,708 KB
testcase_28 AC 141 ms
57,436 KB
testcase_29 AC 179 ms
57,732 KB
testcase_30 AC 142 ms
57,112 KB
testcase_31 AC 205 ms
59,712 KB
testcase_32 AC 150 ms
57,840 KB
testcase_33 AC 204 ms
58,224 KB
testcase_34 AC 144 ms
57,528 KB
testcase_35 AC 203 ms
56,064 KB
testcase_36 AC 183 ms
57,708 KB
testcase_37 AC 150 ms
57,672 KB
testcase_38 AC 168 ms
57,760 KB
testcase_39 AC 161 ms
57,500 KB
testcase_40 AC 211 ms
59,804 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];
		short[] out = new short[n];
		for(int i=0;i<n;i++){
			a[i] = sc.nextShort();
		}
		for(short i =n;i>0;i--){
			partHeap((short)(i-1),a);
		}
		for(short k=n;k>1;k--){
			out[k-1] = a[0];
			a[0] = a[k-1];
			a[k-1] = -10000;
			partHeap((short)0,a);
		}
		
	    double center = -10000;
	    if(n%2==0) center = (out[n/2-1] + out[n/2])/2;
	    else center = out[n/2];
	    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