結果

問題 No.723 2つの数の和
ユーザー TksiTksi
提出日時 2019-03-10 21:11:07
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 284 ms / 2,000 ms
コード長 489 bytes
コンパイル時間 39 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 60,088 KB
最終ジャッジ日時 2024-04-21 02:30:49
合計ジャッジ時間 5,305 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
39,552 KB
testcase_01 AC 62 ms
39,424 KB
testcase_02 AC 62 ms
39,552 KB
testcase_03 AC 232 ms
54,632 KB
testcase_04 AC 281 ms
60,088 KB
testcase_05 AC 258 ms
56,064 KB
testcase_06 AC 276 ms
59,000 KB
testcase_07 AC 152 ms
52,400 KB
testcase_08 AC 165 ms
50,468 KB
testcase_09 AC 284 ms
59,740 KB
testcase_10 AC 158 ms
51,148 KB
testcase_11 AC 85 ms
45,056 KB
testcase_12 AC 188 ms
51,140 KB
testcase_13 AC 282 ms
59,788 KB
testcase_14 AC 121 ms
47,952 KB
testcase_15 AC 156 ms
50,944 KB
testcase_16 AC 208 ms
54,288 KB
testcase_17 AC 249 ms
55,608 KB
testcase_18 AC 187 ms
54,580 KB
testcase_19 AC 216 ms
58,124 KB
testcase_20 AC 63 ms
39,424 KB
testcase_21 AC 62 ms
39,552 KB
testcase_22 AC 64 ms
39,680 KB
testcase_23 AC 227 ms
57,724 KB
testcase_24 AC 129 ms
48,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

const input =   require('fs').readFileSync('/dev/stdin', 'utf8').slice(0,-1);
let [N, X, ...a] = input.split(/\s/);
a = a.map(v => +v).sort((a, b) => a - b);
X = +X;

const binary_search = key => {
  let ng = -1;
  let ok = a.length;
  while (Math.abs(ok - ng) > 1) {
    mid = ng + (ok - ng) / 2 | 0;
    if (a[mid] >= key) ok = mid;
    else ng = mid;
  }
  return ok;
};

let sum = 0;
for (const xx of a) {
  sum += binary_search(X - xx + 1) - binary_search(X - xx);
}
console.log(sum);
0