結果
問題 | No.275 中央値を求めよ |
ユーザー |
|
提出日時 | 2020-07-23 13:13:05 |
言語 | JavaScript (node v23.5.0) |
結果 |
AC
|
実行時間 | 145 ms / 1,000 ms |
コード長 | 1,125 bytes |
コンパイル時間 | 197 ms |
コンパイル使用メモリ | 6,816 KB |
実行使用メモリ | 43,008 KB |
最終ジャッジ日時 | 2024-06-23 17:31:43 |
合計ジャッジ時間 | 4,145 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
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;