結果

問題 No.275 中央値を求めよ
ユーザー Takuya ItoTakuya Ito
提出日時 2022-12-10 13:32:36
言語 TypeScript
(5.4.3)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 912 bytes
コンパイル時間 7,152 ms
コンパイル使用メモリ 256,212 KB
実行使用メモリ 44,260 KB
最終ジャッジ日時 2023-08-05 01:45:45
合計ジャッジ時間 11,439 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
42,508 KB
testcase_01 AC 77 ms
42,460 KB
testcase_02 AC 71 ms
42,484 KB
testcase_03 AC 75 ms
42,248 KB
testcase_04 AC 75 ms
42,340 KB
testcase_05 AC 77 ms
42,484 KB
testcase_06 AC 75 ms
42,396 KB
testcase_07 AC 77 ms
42,192 KB
testcase_08 AC 75 ms
42,304 KB
testcase_09 AC 76 ms
42,204 KB
testcase_10 AC 75 ms
42,556 KB
testcase_11 AC 75 ms
42,400 KB
testcase_12 AC 74 ms
42,164 KB
testcase_13 AC 77 ms
44,260 KB
testcase_14 AC 75 ms
42,396 KB
testcase_15 AC 76 ms
42,540 KB
testcase_16 AC 76 ms
42,304 KB
testcase_17 AC 77 ms
42,284 KB
testcase_18 AC 74 ms
42,580 KB
testcase_19 AC 76 ms
42,204 KB
testcase_20 AC 77 ms
42,252 KB
testcase_21 AC 77 ms
42,448 KB
testcase_22 AC 77 ms
42,600 KB
testcase_23 AC 74 ms
42,224 KB
testcase_24 AC 75 ms
42,544 KB
testcase_25 AC 74 ms
42,656 KB
testcase_26 AC 76 ms
42,296 KB
testcase_27 AC 77 ms
42,348 KB
testcase_28 AC 74 ms
42,332 KB
testcase_29 AC 76 ms
42,224 KB
testcase_30 AC 76 ms
42,244 KB
testcase_31 AC 76 ms
42,296 KB
testcase_32 AC 76 ms
42,320 KB
testcase_33 AC 78 ms
42,208 KB
testcase_34 AC 75 ms
42,204 KB
testcase_35 AC 76 ms
42,456 KB
testcase_36 AC 76 ms
42,476 KB
testcase_37 AC 77 ms
42,292 KB
testcase_38 AC 75 ms
42,252 KB
testcase_39 AC 77 ms
42,440 KB
testcase_40 AC 75 ms
42,276 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function Main(input: string): void {
  // 入力(2行)を受け取り、扱いやすいように処理
  const inputArr = input.split('\n');
  const numCount = parseInt(inputArr[0], 10);
  const nums = inputArr[1].split(' ')
                          .map(str => parseInt(str, 10))
                          .sort((a, b) => a - b);

  // 数値の数が偶数なら、中央に近い2つの値(length/2 番目とその1つ後ろ)の平均
  //         奇数なら、中央値の切り下げ 番目の値
  let median = 0;
  if (numCount % 2 == 0) {
    median = (nums[(numCount / 2) - 1] + nums[numCount / 2]) / 2
  } else {
    median = nums[Math.floor(numCount / 2)];
  }

  // 少数第一位までにする(10倍した数で四捨五入して、それを1/10して少数桁を1つだけ作る)
  console.log(Math.round(median * 10) / 10);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
0