結果

問題 No.275 中央値を求めよ
ユーザー crazybbb3crazybbb3
提出日時 2017-01-31 21:49:22
言語 Java17
(openjdk 17.0.1)
結果
AC  
実行時間 62 ms / 1,000 ms
コード長 1,820 bytes
コンパイル時間 2,479 ms
使用メモリ 35,248 KB
最終ジャッジ日時 2023-01-22 21:58:29
合計ジャッジ時間 6,144 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 49 ms
34,644 KB
testcase_01 AC 49 ms
34,732 KB
testcase_02 AC 49 ms
34,648 KB
testcase_03 AC 48 ms
34,196 KB
testcase_04 AC 49 ms
34,608 KB
testcase_05 AC 49 ms
34,568 KB
testcase_06 AC 49 ms
34,660 KB
testcase_07 AC 53 ms
34,904 KB
testcase_08 AC 49 ms
34,272 KB
testcase_09 AC 49 ms
34,232 KB
testcase_10 AC 50 ms
34,592 KB
testcase_11 AC 48 ms
34,240 KB
testcase_12 AC 48 ms
34,380 KB
testcase_13 AC 48 ms
34,444 KB
testcase_14 AC 47 ms
34,552 KB
testcase_15 AC 62 ms
35,248 KB
testcase_16 AC 59 ms
34,800 KB
testcase_17 AC 58 ms
34,844 KB
testcase_18 AC 52 ms
34,624 KB
testcase_19 AC 53 ms
34,848 KB
testcase_20 AC 56 ms
34,928 KB
testcase_21 AC 51 ms
34,672 KB
testcase_22 AC 56 ms
34,856 KB
testcase_23 AC 53 ms
34,724 KB
testcase_24 AC 52 ms
34,516 KB
testcase_25 AC 57 ms
34,956 KB
testcase_26 AC 55 ms
34,548 KB
testcase_27 AC 54 ms
34,600 KB
testcase_28 AC 49 ms
34,420 KB
testcase_29 AC 52 ms
34,624 KB
testcase_30 AC 48 ms
34,444 KB
testcase_31 AC 56 ms
34,744 KB
testcase_32 AC 49 ms
34,540 KB
testcase_33 AC 54 ms
34,692 KB
testcase_34 AC 48 ms
34,460 KB
testcase_35 AC 54 ms
34,636 KB
testcase_36 AC 51 ms
34,440 KB
testcase_37 AC 50 ms
34,448 KB
testcase_38 AC 50 ms
34,724 KB
testcase_39 AC 51 ms
34,216 KB
testcase_40 AC 59 ms
34,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    void solve() throws IOException {
        int n = ni();
        int[] a = nia(n);
        Arrays.sort(a);

        if (n % 2 == 1) {
            out.println(a[n / 2]);
        } else {
            out.println((a[n / 2 - 1] + a[n / 2]) / 2.0);
        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}
0