結果
| 問題 | No.275 中央値を求めよ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-07-23 13:04:23 |
| 言語 | JavaScript (node v23.5.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 566 bytes |
| 記録 | |
| コンパイル時間 | 291 ms |
| コンパイル使用メモリ | 7,068 KB |
| 実行使用メモリ | 41,340 KB |
| 最終ジャッジ日時 | 2024-06-23 17:31:01 |
| 合計ジャッジ時間 | 4,118 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 WA * 1 |
| other | AC * 6 WA * 32 |
ソースコード
function main(input = '') {
if (!input) throw Error;
let lines = input.split('\n');
let length = parseInt(lines[0]);
let nums = lines[1]
.split(' ')
.map((val) => parseInt(val))
.sort();
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;