結果

問題 No.275 中央値を求めよ
ユーザー brave_reverse_brave_reverse_
提出日時 2016-01-08 15:30:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 212 ms / 1,000 ms
コード長 1,081 bytes
コンパイル時間 3,837 ms
コンパイル使用メモリ 78,768 KB
実行使用メモリ 58,916 KB
最終ジャッジ日時 2023-09-07 05:09:24
合計ジャッジ時間 11,523 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,052 KB
testcase_01 AC 123 ms
55,864 KB
testcase_02 AC 141 ms
55,856 KB
testcase_03 AC 121 ms
55,780 KB
testcase_04 AC 124 ms
56,008 KB
testcase_05 AC 125 ms
55,816 KB
testcase_06 AC 136 ms
55,724 KB
testcase_07 AC 188 ms
56,228 KB
testcase_08 AC 143 ms
55,468 KB
testcase_09 AC 145 ms
56,048 KB
testcase_10 AC 145 ms
56,000 KB
testcase_11 AC 126 ms
56,056 KB
testcase_12 AC 130 ms
55,644 KB
testcase_13 AC 125 ms
55,724 KB
testcase_14 AC 127 ms
55,472 KB
testcase_15 AC 206 ms
58,540 KB
testcase_16 AC 197 ms
58,536 KB
testcase_17 AC 199 ms
58,472 KB
testcase_18 AC 156 ms
56,008 KB
testcase_19 AC 199 ms
56,480 KB
testcase_20 AC 198 ms
58,604 KB
testcase_21 AC 173 ms
56,268 KB
testcase_22 AC 200 ms
58,328 KB
testcase_23 AC 175 ms
55,932 KB
testcase_24 AC 155 ms
55,848 KB
testcase_25 AC 212 ms
58,916 KB
testcase_26 AC 201 ms
58,760 KB
testcase_27 AC 200 ms
58,764 KB
testcase_28 AC 137 ms
55,700 KB
testcase_29 AC 160 ms
55,912 KB
testcase_30 AC 136 ms
55,612 KB
testcase_31 AC 199 ms
58,660 KB
testcase_32 AC 146 ms
56,308 KB
testcase_33 AC 198 ms
58,180 KB
testcase_34 AC 138 ms
55,472 KB
testcase_35 AC 200 ms
58,280 KB
testcase_36 AC 157 ms
56,424 KB
testcase_37 AC 144 ms
55,728 KB
testcase_38 AC 158 ms
55,684 KB
testcase_39 AC 157 ms
56,044 KB
testcase_40 AC 208 ms
58,620 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