結果

問題 No.275 中央値を求めよ
ユーザー yu0912yu0912
提出日時 2020-07-23 13:13:05
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 80 ms / 1,000 ms
コード長 1,125 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 5,336 KB
実行使用メモリ 42,652 KB
最終ジャッジ日時 2023-09-05 22:11:14
合計ジャッジ時間 4,873 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
42,384 KB
testcase_01 AC 74 ms
42,432 KB
testcase_02 AC 74 ms
42,292 KB
testcase_03 AC 73 ms
42,328 KB
testcase_04 AC 75 ms
42,228 KB
testcase_05 AC 76 ms
42,556 KB
testcase_06 AC 76 ms
42,024 KB
testcase_07 AC 77 ms
42,236 KB
testcase_08 AC 77 ms
42,212 KB
testcase_09 AC 75 ms
42,104 KB
testcase_10 AC 78 ms
42,408 KB
testcase_11 AC 77 ms
42,056 KB
testcase_12 AC 75 ms
42,084 KB
testcase_13 AC 77 ms
42,140 KB
testcase_14 AC 77 ms
42,252 KB
testcase_15 AC 78 ms
42,652 KB
testcase_16 AC 76 ms
42,356 KB
testcase_17 AC 77 ms
42,288 KB
testcase_18 AC 78 ms
42,368 KB
testcase_19 AC 77 ms
42,168 KB
testcase_20 AC 77 ms
42,060 KB
testcase_21 AC 78 ms
42,384 KB
testcase_22 AC 78 ms
42,504 KB
testcase_23 AC 77 ms
42,076 KB
testcase_24 AC 78 ms
42,400 KB
testcase_25 AC 78 ms
42,564 KB
testcase_26 AC 78 ms
42,068 KB
testcase_27 AC 78 ms
42,128 KB
testcase_28 AC 76 ms
42,024 KB
testcase_29 AC 77 ms
42,120 KB
testcase_30 AC 76 ms
42,260 KB
testcase_31 AC 77 ms
42,132 KB
testcase_32 AC 78 ms
42,108 KB
testcase_33 AC 80 ms
42,220 KB
testcase_34 AC 76 ms
42,136 KB
testcase_35 AC 76 ms
42,060 KB
testcase_36 AC 77 ms
42,208 KB
testcase_37 AC 76 ms
42,092 KB
testcase_38 AC 77 ms
42,044 KB
testcase_39 AC 76 ms
42,200 KB
testcase_40 AC 78 ms
42,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(
  input = `126
-999 266 169 -939 497 645 659 -210 300 834 400 1000 -68 -187 156 -579 79 -985 246 704 98 74 53 746 -219 80 482 -645 12 707 -702 212 719 915 175 61 -599 683 -85 -672 948 -335 -685 -897 327 659 192 -85 723 -363 -190 -734 648 975 566 -237 450 -664 -89 891 789 -13 538 328 974 380 48 968 397 554 -659 872 -100 28 986 717 964 99 -646 100 -590 453 930 337 -758 -137 -945 -66 -541 773 222 919 822 790 -916 -250 -510 604 392 756 428 990 535 -935 166 -170 -889 -304 164 555 337 -201 -942 -36 973 742 294 842 473 -151 -961 452 -8 -656 -653 -286
`
) {
  if (!input) throw Error;

  let lines = input.split('\n');
  let length = parseInt(lines[0]);
  let nums = lines[1]
    .split(' ')
    .map((val) => parseInt(val))
    .sort((a, b) => a - b);

  if (length % 2 === 0) {
    return `${(nums[length / 2] + nums[length / 2 - 1]) / 2}`;
  } else {
    return `${nums[Math.floor(length / 2)]}`;
  }
}

const { readFileSync, existsSync } = require('fs');
const stdin = '/dev/stdin';

if (existsSync(stdin)) {
  const input = readFileSync(stdin, 'utf8');
  console.log(main(input));
}

module.exports = main;
0