結果
問題 | No.275 中央値を求めよ |
ユーザー |
![]() |
提出日時 | 2018-06-03 16:58:35 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 186 ms / 1,000 ms |
コード長 | 532 bytes |
コンパイル時間 | 2,141 ms |
コンパイル使用メモリ | 74,276 KB |
実行使用メモリ | 42,896 KB |
最終ジャッジ日時 | 2024-06-25 01:39:37 |
合計ジャッジ時間 | 9,623 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
import java.util.Arrays; import java.util.Scanner; class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = scan.nextInt(); } Arrays.sort(a); int j = n / 2; if (n % 2 != 0) { System.out.println(a[j]); } else { System.out.println((double)(a[j - 1] + a[j]) / 2); } scan.close(); } }