結果

問題 No.275 中央値を求めよ
ユーザー dogwood0424dogwood0424
提出日時 2017-11-29 12:53:03
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 1,000 ms
コード長 802 bytes
コンパイル時間 3,924 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 56,888 KB
最終ジャッジ日時 2023-09-07 06:22:01
合計ジャッジ時間 11,993 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,524 KB
testcase_01 AC 125 ms
55,788 KB
testcase_02 AC 137 ms
55,568 KB
testcase_03 AC 126 ms
55,396 KB
testcase_04 AC 124 ms
55,360 KB
testcase_05 AC 124 ms
55,692 KB
testcase_06 AC 137 ms
55,904 KB
testcase_07 AC 182 ms
56,296 KB
testcase_08 AC 140 ms
53,696 KB
testcase_09 AC 143 ms
55,372 KB
testcase_10 AC 145 ms
55,652 KB
testcase_11 AC 127 ms
55,432 KB
testcase_12 AC 127 ms
55,596 KB
testcase_13 AC 125 ms
55,672 KB
testcase_14 AC 125 ms
55,596 KB
testcase_15 AC 184 ms
56,628 KB
testcase_16 AC 180 ms
55,848 KB
testcase_17 AC 187 ms
56,524 KB
testcase_18 AC 156 ms
55,764 KB
testcase_19 AC 180 ms
56,072 KB
testcase_20 AC 174 ms
56,472 KB
testcase_21 AC 154 ms
55,820 KB
testcase_22 AC 173 ms
56,476 KB
testcase_23 AC 176 ms
55,832 KB
testcase_24 AC 152 ms
55,892 KB
testcase_25 AC 183 ms
56,292 KB
testcase_26 AC 182 ms
55,800 KB
testcase_27 AC 180 ms
56,148 KB
testcase_28 AC 138 ms
55,356 KB
testcase_29 AC 162 ms
55,628 KB
testcase_30 AC 135 ms
55,360 KB
testcase_31 AC 184 ms
55,916 KB
testcase_32 AC 144 ms
56,128 KB
testcase_33 AC 190 ms
56,072 KB
testcase_34 AC 135 ms
55,764 KB
testcase_35 AC 178 ms
55,612 KB
testcase_36 AC 176 ms
56,556 KB
testcase_37 AC 142 ms
56,088 KB
testcase_38 AC 164 ms
56,176 KB
testcase_39 AC 155 ms
55,828 KB
testcase_40 AC 186 ms
56,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No275{
	static void swap(int[]a,int idx1,int idx2) {
		int t = a[idx1];	a[idx1]=a[idx2];	a[idx2]=t;
	}
	static void quickSort(int[]a,int left,int right) {
		int pl = left;
		int pr = right;
		int x = a[(pl+pr)/2];

		do {
			while(a[pl]<x) pl++;
			while(a[pr]>x) pr--;
			if(pl <= pr)
				swap(a,pl++,pr--);
		}while(pl<=pr);

		if(left<pr) quickSort(a,left,pr);
		if(pl<right)quickSort(a,pl,right);
	}

	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int []a = new int [n];
		for(int i=0;i<n;i++) {
			a[i] = sc.nextInt();
		}

		quickSort(a,0,n-1);

		double med=0.0;

		if(n%2==0) {
			med = (a[(n/2)-1]+a[n/2])/2.0;
		}
		else if(n%2!=0) {
			med = a[n/2];
			}

		System.out.println(med);


	}

}
0