結果

問題 No.275 中央値を求めよ
ユーザー Takuya-AmpiTakuya-Ampi
提出日時 2020-03-24 19:59:57
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 96 ms / 1,000 ms
コード長 585 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 44,288 KB
最終ジャッジ日時 2024-04-21 03:15:43
合計ジャッジ時間 4,819 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
40,064 KB
testcase_01 AC 78 ms
40,576 KB
testcase_02 AC 78 ms
40,448 KB
testcase_03 AC 82 ms
40,320 KB
testcase_04 AC 77 ms
40,576 KB
testcase_05 AC 79 ms
40,064 KB
testcase_06 AC 79 ms
40,448 KB
testcase_07 AC 81 ms
43,776 KB
testcase_08 AC 78 ms
40,704 KB
testcase_09 AC 78 ms
39,936 KB
testcase_10 AC 80 ms
40,832 KB
testcase_11 AC 79 ms
39,936 KB
testcase_12 AC 79 ms
40,704 KB
testcase_13 AC 78 ms
40,704 KB
testcase_14 AC 77 ms
40,320 KB
testcase_15 AC 82 ms
43,648 KB
testcase_16 AC 78 ms
40,192 KB
testcase_17 AC 80 ms
40,448 KB
testcase_18 AC 77 ms
40,576 KB
testcase_19 AC 80 ms
43,904 KB
testcase_20 AC 81 ms
43,648 KB
testcase_21 AC 84 ms
44,032 KB
testcase_22 AC 81 ms
44,288 KB
testcase_23 AC 79 ms
43,776 KB
testcase_24 AC 78 ms
40,832 KB
testcase_25 AC 80 ms
44,032 KB
testcase_26 AC 80 ms
43,776 KB
testcase_27 AC 82 ms
43,904 KB
testcase_28 AC 78 ms
40,192 KB
testcase_29 AC 82 ms
43,648 KB
testcase_30 AC 79 ms
40,576 KB
testcase_31 AC 81 ms
43,520 KB
testcase_32 AC 78 ms
40,448 KB
testcase_33 AC 79 ms
43,392 KB
testcase_34 AC 77 ms
40,320 KB
testcase_35 AC 78 ms
44,160 KB
testcase_36 AC 79 ms
44,160 KB
testcase_37 AC 78 ms
40,320 KB
testcase_38 AC 76 ms
40,320 KB
testcase_39 AC 79 ms
40,704 KB
testcase_40 AC 81 ms
44,160 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