結果

問題 No.723 2つの数の和
ユーザー TksiTksi
提出日時 2019-03-10 23:39:44
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 1,013 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 6,816 KB
実行使用メモリ 59,452 KB
最終ジャッジ日時 2024-04-21 02:31:02
合計ジャッジ時間 4,789 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
38,784 KB
testcase_01 AC 58 ms
38,912 KB
testcase_02 AC 59 ms
39,040 KB
testcase_03 AC 205 ms
54,460 KB
testcase_04 AC 263 ms
59,452 KB
testcase_05 AC 226 ms
55,644 KB
testcase_06 AC 239 ms
58,356 KB
testcase_07 AC 143 ms
49,940 KB
testcase_08 AC 150 ms
51,196 KB
testcase_09 AC 250 ms
59,360 KB
testcase_10 AC 141 ms
50,380 KB
testcase_11 AC 79 ms
45,568 KB
testcase_12 AC 166 ms
50,704 KB
testcase_13 AC 261 ms
59,052 KB
testcase_14 AC 113 ms
46,804 KB
testcase_15 AC 151 ms
50,724 KB
testcase_16 AC 187 ms
53,212 KB
testcase_17 AC 224 ms
55,128 KB
testcase_18 AC 188 ms
54,336 KB
testcase_19 AC 212 ms
57,624 KB
testcase_20 AC 59 ms
38,912 KB
testcase_21 AC 61 ms
38,656 KB
testcase_22 AC 60 ms
38,912 KB
testcase_23 AC 215 ms
57,860 KB
testcase_24 AC 121 ms
47,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Array.prototype.indexOf = function (num) {
  let left = 0;
  let right = this.length - 1;
  for (;;) {
    if (right < left) return -1;
    const mid = (right - left) / 2 + left | 0;
    if (this[mid] === num && (mid == 0 || this[mid - 1] !== this[mid])) return mid
    if (num <= this[mid]) right = mid - 1;
    else left = mid + 1;
  }
};

Array.prototype.lastIndexOf = function (num) {
  let left = 0;
  let right = this.length - 1;
  for (;;) {
    if (right < left) return -1;
    const mid = (right - left) / 2 + left | 0;
    if (this[mid] === num && (mid == this.length - 1 || this[mid + 1] !== this[mid])) return mid
    if (num < this[mid]) right = mid - 1;
    else left = mid + 1;
  }
};

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);

let sum = 0;
for (const v of a) {
  const index = a.indexOf(X - v);
  sum += index >= 0 ? a.lastIndexOf(X - v) - index + 1 : 0;
}
console.log(sum);
0