結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
42,836 KB
testcase_01 AC 85 ms
42,808 KB
testcase_02 AC 80 ms
42,872 KB
testcase_03 AC 77 ms
42,564 KB
testcase_04 AC 83 ms
42,568 KB
testcase_05 AC 77 ms
42,960 KB
testcase_06 AC 77 ms
42,504 KB
testcase_07 AC 78 ms
42,680 KB
testcase_08 AC 80 ms
44,564 KB
testcase_09 AC 81 ms
42,580 KB
testcase_10 AC 79 ms
42,860 KB
testcase_11 AC 80 ms
42,824 KB
testcase_12 AC 78 ms
42,676 KB
testcase_13 AC 79 ms
42,704 KB
testcase_14 AC 80 ms
42,792 KB
testcase_15 AC 81 ms
43,084 KB
testcase_16 AC 77 ms
42,748 KB
testcase_17 AC 80 ms
42,732 KB
testcase_18 AC 77 ms
43,016 KB
testcase_19 AC 77 ms
42,804 KB
testcase_20 AC 76 ms
42,876 KB
testcase_21 AC 81 ms
45,032 KB
testcase_22 AC 84 ms
42,932 KB
testcase_23 AC 78 ms
42,672 KB
testcase_24 AC 78 ms
42,836 KB
testcase_25 AC 81 ms
42,928 KB
testcase_26 AC 77 ms
42,720 KB
testcase_27 AC 78 ms
42,776 KB
testcase_28 AC 76 ms
42,560 KB
testcase_29 AC 78 ms
42,792 KB
testcase_30 AC 79 ms
42,672 KB
testcase_31 AC 86 ms
42,752 KB
testcase_32 AC 82 ms
42,588 KB
testcase_33 AC 83 ms
42,740 KB
testcase_34 AC 79 ms
42,560 KB
testcase_35 AC 78 ms
42,704 KB
testcase_36 AC 79 ms
42,660 KB
testcase_37 AC 78 ms
42,692 KB
testcase_38 AC 78 ms
42,560 KB
testcase_39 AC 76 ms
42,720 KB
testcase_40 AC 78 ms
42,688 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