結果

問題 No.275 中央値を求めよ
ユーザー samplelpmassamplelpmas
提出日時 2016-12-16 09:22:11
言語 Java21
(openjdk 21)
結果
AC  
実行時間 191 ms / 1,000 ms
コード長 636 bytes
コンパイル時間 1,961 ms
コンパイル使用メモリ 71,976 KB
実行使用メモリ 56,720 KB
最終ジャッジ日時 2023-09-07 05:43:58
合計ジャッジ時間 9,973 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,968 KB
testcase_01 AC 125 ms
55,836 KB
testcase_02 AC 140 ms
55,912 KB
testcase_03 AC 126 ms
55,584 KB
testcase_04 AC 126 ms
56,152 KB
testcase_05 AC 125 ms
53,752 KB
testcase_06 AC 134 ms
56,068 KB
testcase_07 AC 185 ms
56,136 KB
testcase_08 AC 139 ms
56,060 KB
testcase_09 AC 143 ms
56,112 KB
testcase_10 AC 141 ms
55,768 KB
testcase_11 AC 124 ms
55,800 KB
testcase_12 AC 126 ms
55,828 KB
testcase_13 AC 125 ms
55,980 KB
testcase_14 AC 126 ms
55,832 KB
testcase_15 AC 190 ms
55,988 KB
testcase_16 AC 186 ms
56,284 KB
testcase_17 AC 186 ms
56,720 KB
testcase_18 AC 153 ms
55,732 KB
testcase_19 AC 191 ms
56,032 KB
testcase_20 AC 183 ms
56,616 KB
testcase_21 AC 169 ms
55,860 KB
testcase_22 AC 187 ms
54,340 KB
testcase_23 AC 156 ms
56,428 KB
testcase_24 AC 157 ms
55,816 KB
testcase_25 AC 191 ms
56,216 KB
testcase_26 AC 185 ms
56,448 KB
testcase_27 AC 182 ms
56,544 KB
testcase_28 AC 136 ms
56,008 KB
testcase_29 AC 168 ms
56,036 KB
testcase_30 AC 135 ms
55,832 KB
testcase_31 AC 184 ms
56,356 KB
testcase_32 AC 142 ms
55,824 KB
testcase_33 AC 182 ms
55,752 KB
testcase_34 AC 135 ms
55,928 KB
testcase_35 AC 187 ms
56,012 KB
testcase_36 AC 176 ms
56,056 KB
testcase_37 AC 140 ms
55,716 KB
testcase_38 AC 160 ms
56,020 KB
testcase_39 AC 151 ms
56,320 KB
testcase_40 AC 189 ms
56,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {

    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();
        }

        Arrays.sort(A);

        double median;

        if ((N % 2) == 0) {

            int midpoint1 = A[N / 2 - 1];
            int midpoint2 = A[N / 2];

            median = (double) (midpoint1 + midpoint2) / 2;

        } else {

            median = A[N / 2];

        }

        System.out.println(median);

    }

}
0