結果

問題 No.275 中央値を求めよ
コンテスト
ユーザー Lo_OT
提出日時 2018-03-22 22:42:59
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
AC  
実行時間 107 ms / 1,000 ms
コード長 1,305 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,828 ms
コンパイル使用メモリ 84,844 KB
実行使用メモリ 50,172 KB
最終ジャッジ日時 2026-03-11 05:41:04
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Yukicoder solver = new Yukicoder();
        solver.solve(1, in, out);
        out.close();
    }

    static class Yukicoder {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int loops = in.nextInt();
            List<Integer> arr = new ArrayList<Integer>();

            for (int i = 0; i < loops; i++) {
                arr.add(in.nextInt());
            }
            Collections.sort(arr);


            if (loops % 2 == 0) {
                int median = loops / 2;
                out.println((arr.get(median - 1) + arr.get(median)) / 2.0);
            } else {
                int median = (int) Math.floor(loops / 2);
                out.println(arr.get(median));
            }
        }

    }
}

0