結果

問題 No.275 中央値を求めよ
ユーザー yu0912yu0912
提出日時 2020-07-23 13:12:13
言語 JavaScript
(node v21.7.1)
結果
WA  
実行時間 -
コード長 1,124 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 5,324 KB
実行使用メモリ 44,240 KB
最終ジャッジ日時 2023-09-05 22:10:41
合計ジャッジ時間 5,171 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
42,596 KB
testcase_01 AC 75 ms
42,408 KB
testcase_02 AC 76 ms
42,352 KB
testcase_03 WA -
testcase_04 AC 75 ms
42,080 KB
testcase_05 AC 80 ms
42,348 KB
testcase_06 AC 75 ms
42,120 KB
testcase_07 AC 75 ms
42,112 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 72 ms
42,452 KB
testcase_11 WA -
testcase_12 AC 75 ms
42,296 KB
testcase_13 WA -
testcase_14 AC 75 ms
42,284 KB
testcase_15 AC 76 ms
42,424 KB
testcase_16 AC 76 ms
42,136 KB
testcase_17 AC 75 ms
42,288 KB
testcase_18 AC 76 ms
42,304 KB
testcase_19 WA -
testcase_20 AC 76 ms
42,164 KB
testcase_21 AC 75 ms
42,532 KB
testcase_22 AC 76 ms
42,400 KB
testcase_23 WA -
testcase_24 AC 75 ms
42,360 KB
testcase_25 AC 77 ms
42,420 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 75 ms
42,048 KB
testcase_30 AC 74 ms
42,100 KB
testcase_31 AC 75 ms
42,180 KB
testcase_32 AC 74 ms
42,316 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 77 ms
42,288 KB
testcase_38 AC 74 ms
42,104 KB
testcase_39 WA -
testcase_40 AC 76 ms
42,416 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.ceil(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