結果
問題 | No.275 中央値を求めよ |
ユーザー | dazy |
提出日時 | 2016-09-02 21:06:57 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 206 ms / 1,000 ms |
コード長 | 1,488 bytes |
コンパイル時間 | 2,069 ms |
コンパイル使用メモリ | 74,424 KB |
実行使用メモリ | 56,800 KB |
最終ジャッジ日時 | 2023-09-07 05:34:52 |
合計ジャッジ時間 | 10,526 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 127 ms
55,804 KB |
testcase_01 | AC | 128 ms
55,972 KB |
testcase_02 | AC | 142 ms
55,740 KB |
testcase_03 | AC | 127 ms
55,688 KB |
testcase_04 | AC | 126 ms
55,912 KB |
testcase_05 | AC | 124 ms
55,860 KB |
testcase_06 | AC | 135 ms
55,496 KB |
testcase_07 | AC | 197 ms
56,032 KB |
testcase_08 | AC | 144 ms
55,812 KB |
testcase_09 | AC | 144 ms
55,552 KB |
testcase_10 | AC | 145 ms
53,976 KB |
testcase_11 | AC | 125 ms
55,656 KB |
testcase_12 | AC | 125 ms
55,756 KB |
testcase_13 | AC | 124 ms
55,784 KB |
testcase_14 | AC | 125 ms
55,760 KB |
testcase_15 | AC | 203 ms
56,800 KB |
testcase_16 | AC | 202 ms
56,400 KB |
testcase_17 | AC | 201 ms
56,592 KB |
testcase_18 | AC | 158 ms
56,068 KB |
testcase_19 | AC | 195 ms
56,352 KB |
testcase_20 | AC | 196 ms
56,364 KB |
testcase_21 | AC | 158 ms
56,256 KB |
testcase_22 | AC | 198 ms
56,796 KB |
testcase_23 | AC | 174 ms
55,984 KB |
testcase_24 | AC | 153 ms
55,916 KB |
testcase_25 | AC | 200 ms
56,440 KB |
testcase_26 | AC | 198 ms
56,192 KB |
testcase_27 | AC | 199 ms
56,464 KB |
testcase_28 | AC | 137 ms
55,584 KB |
testcase_29 | AC | 176 ms
56,152 KB |
testcase_30 | AC | 136 ms
55,744 KB |
testcase_31 | AC | 202 ms
56,424 KB |
testcase_32 | AC | 146 ms
55,900 KB |
testcase_33 | AC | 198 ms
56,292 KB |
testcase_34 | AC | 138 ms
55,864 KB |
testcase_35 | AC | 198 ms
56,512 KB |
testcase_36 | AC | 177 ms
55,900 KB |
testcase_37 | AC | 146 ms
55,752 KB |
testcase_38 | AC | 156 ms
55,840 KB |
testcase_39 | AC | 157 ms
55,428 KB |
testcase_40 | AC | 206 ms
56,316 KB |
ソースコード
import java.lang.reflect.Array; import java.util.Arrays; import java.util.Scanner; class Yukicoder { static public void main(String[] args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); if (N < 1 || N > 1000) System.exit(1); int[] A = new int[N]; for (int i = 0; i < N; i++) { A[i] = scanner.nextInt(); if (A[i] < -1000 || A[i] > 1000) System.exit(1); } for (int i = N; i > 1; i--) { heapSort(i, A); swap(A, 0, i-1); } float mid; if (N%2 == 1) mid = A[N/2]; else mid = (((float) A[N / 2 - 1]) + A[N/2])/2; System.out.println(mid); } static public void heapSort (int leaf, int[] A) { int root = leaf/2-1; int tmp; for (int i = root; i >= 0; i--) { while ((root+1)*2 <= leaf) { if ((root+1)*2 == leaf) { tmp = (root+1)*2 - 1; } else { if (A[(root+1)*2 - 1] < A[(root+1)*2]) tmp = (root+1)*2; else tmp = (root+1)*2 - 1; } if (A[root] < A[tmp]) { swap(A, root, tmp); root = tmp; } else break; } root = i - 1; } } static private void swap (int[] A, int a, int b){ int tmp; tmp = A[a]; A[a] = A[b]; A[b] = tmp; } }