結果

問題 No.275 中央値を求めよ
ユーザー Takuya-Ampi
提出日時 2020-03-24 19:59:57
言語 JavaScript
(node v23.5.0)
結果
AC  
実行時間 79 ms / 1,000 ms
コード長 585 bytes
コンパイル時間 42 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 45,880 KB
最終ジャッジ日時 2024-10-13 01:36:24
合計ジャッジ時間 4,177 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

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