結果

問題 No.275 中央値を求めよ
ユーザー syusyu
提出日時 2020-08-25 20:01:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 170 ms / 1,000 ms
コード長 619 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 80,872 KB
実行使用メモリ 42,912 KB
最終ジャッジ日時 2024-04-24 04:46:00
合計ジャッジ時間 8,624 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
40,420 KB
testcase_01 AC 99 ms
40,292 KB
testcase_02 AC 122 ms
42,004 KB
testcase_03 AC 110 ms
41,204 KB
testcase_04 AC 103 ms
40,300 KB
testcase_05 AC 109 ms
41,268 KB
testcase_06 AC 119 ms
41,176 KB
testcase_07 AC 151 ms
42,000 KB
testcase_08 AC 121 ms
41,840 KB
testcase_09 AC 122 ms
41,464 KB
testcase_10 AC 128 ms
41,748 KB
testcase_11 AC 110 ms
40,332 KB
testcase_12 AC 100 ms
40,576 KB
testcase_13 AC 102 ms
40,520 KB
testcase_14 AC 114 ms
41,596 KB
testcase_15 AC 163 ms
42,528 KB
testcase_16 AC 160 ms
42,724 KB
testcase_17 AC 163 ms
42,652 KB
testcase_18 AC 139 ms
41,800 KB
testcase_19 AC 153 ms
42,172 KB
testcase_20 AC 164 ms
42,580 KB
testcase_21 AC 157 ms
42,048 KB
testcase_22 AC 159 ms
42,492 KB
testcase_23 AC 151 ms
41,840 KB
testcase_24 AC 127 ms
41,912 KB
testcase_25 AC 166 ms
42,796 KB
testcase_26 AC 160 ms
42,648 KB
testcase_27 AC 157 ms
42,024 KB
testcase_28 AC 121 ms
41,472 KB
testcase_29 AC 143 ms
41,988 KB
testcase_30 AC 119 ms
41,888 KB
testcase_31 AC 155 ms
42,708 KB
testcase_32 AC 128 ms
42,032 KB
testcase_33 AC 160 ms
42,812 KB
testcase_34 AC 120 ms
41,208 KB
testcase_35 AC 160 ms
42,764 KB
testcase_36 AC 153 ms
41,988 KB
testcase_37 AC 122 ms
41,756 KB
testcase_38 AC 149 ms
41,724 KB
testcase_39 AC 159 ms
41,884 KB
testcase_40 AC 170 ms
42,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[] numbers=new int[n];
        for(int i=0;i<n;i++){
            numbers[i]=sc.nextInt();
        }
        Arrays.sort(numbers);
        //System.out.println(Arrays.toString(numbers));
        
        int index=n/2;
        
        if(numbers.length%2==1){
            System.out.println(numbers[index]);
        }else{
            double median=(double)(numbers[index-1]+numbers[index])/2;
            System.out.println(median);
        }
    }
}
0