結果

問題 No.275 中央値を求めよ
ユーザー ikawaiikawai
提出日時 2023-09-04 14:27:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 232 ms / 1,000 ms
コード長 648 bytes
コンパイル時間 4,927 ms
コンパイル使用メモリ 74,664 KB
実行使用メモリ 58,184 KB
最終ジャッジ日時 2023-09-04 14:28:09
合計ジャッジ時間 13,709 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 156 ms
55,704 KB
testcase_01 AC 127 ms
53,968 KB
testcase_02 AC 143 ms
55,736 KB
testcase_03 AC 128 ms
55,768 KB
testcase_04 AC 128 ms
55,700 KB
testcase_05 AC 131 ms
55,996 KB
testcase_06 AC 142 ms
55,860 KB
testcase_07 AC 217 ms
55,684 KB
testcase_08 AC 144 ms
55,688 KB
testcase_09 AC 145 ms
55,708 KB
testcase_10 AC 147 ms
55,828 KB
testcase_11 AC 134 ms
55,992 KB
testcase_12 AC 128 ms
56,036 KB
testcase_13 AC 130 ms
55,688 KB
testcase_14 AC 132 ms
55,712 KB
testcase_15 AC 206 ms
56,836 KB
testcase_16 AC 200 ms
56,452 KB
testcase_17 AC 201 ms
56,632 KB
testcase_18 AC 161 ms
55,864 KB
testcase_19 AC 191 ms
55,776 KB
testcase_20 AC 232 ms
56,616 KB
testcase_21 AC 166 ms
56,280 KB
testcase_22 AC 196 ms
55,700 KB
testcase_23 AC 166 ms
56,288 KB
testcase_24 AC 157 ms
56,088 KB
testcase_25 AC 199 ms
56,120 KB
testcase_26 AC 229 ms
56,296 KB
testcase_27 AC 194 ms
58,184 KB
testcase_28 AC 143 ms
55,876 KB
testcase_29 AC 166 ms
56,208 KB
testcase_30 AC 142 ms
55,732 KB
testcase_31 AC 195 ms
54,068 KB
testcase_32 AC 179 ms
55,816 KB
testcase_33 AC 194 ms
56,092 KB
testcase_34 AC 143 ms
55,484 KB
testcase_35 AC 200 ms
56,604 KB
testcase_36 AC 191 ms
56,644 KB
testcase_37 AC 147 ms
55,648 KB
testcase_38 AC 186 ms
55,868 KB
testcase_39 AC 156 ms
55,924 KB
testcase_40 AC 198 ms
56,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.ArrayList;
import java.util.List;
import java.util.Collections;

class Wandbox
{
    public static void main(String[] args)
    {
    	Scanner sc = new Scanner(System.in);
    	
    	List<Integer> list = new ArrayList<>();
    	
    	int n = sc.nextInt();
    	double ans = 0;
    	
    	for (int i = 0; i < n; i++) {
    		
    		list.add(sc.nextInt());
    	} 
    	Collections.sort(list);
    	
    	if (n % 2 == 0) {
    		n /= 2;
    		ans = (double)(list.get(n - 1) + list.get(n)) / 2;
    		System.out.println(ans);
    	} else {
    		n /= 2 ;
    		System.out.println(list.get(n));
    	}
    }
}
0