結果

問題 No.275 中央値を求めよ
ユーザー Takuya-AmpiTakuya-Ampi
提出日時 2020-03-24 20:02:01
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 88 ms / 1,000 ms
コード長 585 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 5,456 KB
実行使用メモリ 44,912 KB
最終ジャッジ日時 2023-08-03 03:44:31
合計ジャッジ時間 4,855 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
42,988 KB
testcase_01 AC 88 ms
42,992 KB
testcase_02 AC 79 ms
42,868 KB
testcase_03 AC 79 ms
42,592 KB
testcase_04 AC 77 ms
42,772 KB
testcase_05 AC 82 ms
42,908 KB
testcase_06 AC 78 ms
42,768 KB
testcase_07 AC 79 ms
42,904 KB
testcase_08 AC 81 ms
42,700 KB
testcase_09 AC 80 ms
42,608 KB
testcase_10 AC 83 ms
42,828 KB
testcase_11 AC 81 ms
42,592 KB
testcase_12 AC 78 ms
42,760 KB
testcase_13 AC 79 ms
42,588 KB
testcase_14 AC 78 ms
42,824 KB
testcase_15 AC 83 ms
42,992 KB
testcase_16 AC 85 ms
42,740 KB
testcase_17 AC 81 ms
42,764 KB
testcase_18 AC 83 ms
42,872 KB
testcase_19 AC 81 ms
42,744 KB
testcase_20 AC 82 ms
42,948 KB
testcase_21 AC 81 ms
43,224 KB
testcase_22 AC 79 ms
43,028 KB
testcase_23 AC 81 ms
42,576 KB
testcase_24 AC 82 ms
42,932 KB
testcase_25 AC 87 ms
43,024 KB
testcase_26 AC 83 ms
42,760 KB
testcase_27 AC 86 ms
42,860 KB
testcase_28 AC 81 ms
42,684 KB
testcase_29 AC 81 ms
42,892 KB
testcase_30 AC 83 ms
42,848 KB
testcase_31 AC 79 ms
42,732 KB
testcase_32 AC 83 ms
42,748 KB
testcase_33 AC 79 ms
42,820 KB
testcase_34 AC 81 ms
42,584 KB
testcase_35 AC 79 ms
44,912 KB
testcase_36 AC 81 ms
42,608 KB
testcase_37 AC 81 ms
42,604 KB
testcase_38 AC 79 ms
42,656 KB
testcase_39 AC 79 ms
42,712 KB
testcase_40 AC 83 ms
42,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
let lines = [];
reader.on("line", line => {
  lines.push(line);
});
reader.on("close", () => {
  const num = parseInt(lines[0])
  const arr = lines[1].split(' ').map(str => parseInt(str, 10))
  const evenCenter1 = num / 2 - 1
  const evenCenter2 = num / 2
  const oddCenter = Math.ceil((num / 2) - 1)
  const cmpFunc = (a, b) => {
    return a - b
  }
  arr.sort(cmpFunc)
  num % 2 === 0 ? console.log((arr[evenCenter1] + arr[evenCenter2]) / 2) : console.log(arr[oddCenter])
});
0