結果

問題 No.723 2つの数の和
ユーザー jp_stejp_ste
提出日時 2020-05-07 21:26:38
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 2,942 bytes
コンパイル時間 97 ms
コンパイル使用メモリ 7,068 KB
実行使用メモリ 60,504 KB
最終ジャッジ日時 2024-04-21 03:28:09
合計ジャッジ時間 3,922 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
47,232 KB
testcase_01 AC 81 ms
47,144 KB
testcase_02 AC 82 ms
47,140 KB
testcase_03 AC 125 ms
57,016 KB
testcase_04 AC 145 ms
58,176 KB
testcase_05 AC 140 ms
57,600 KB
testcase_06 AC 141 ms
57,880 KB
testcase_07 AC 106 ms
52,984 KB
testcase_08 AC 112 ms
54,572 KB
testcase_09 AC 143 ms
58,432 KB
testcase_10 AC 109 ms
53,356 KB
testcase_11 AC 87 ms
51,200 KB
testcase_12 AC 111 ms
54,868 KB
testcase_13 AC 141 ms
58,448 KB
testcase_14 AC 97 ms
52,224 KB
testcase_15 AC 108 ms
52,864 KB
testcase_16 AC 121 ms
56,332 KB
testcase_17 AC 130 ms
57,468 KB
testcase_18 AC 116 ms
54,324 KB
testcase_19 AC 149 ms
60,504 KB
testcase_20 AC 81 ms
47,016 KB
testcase_21 AC 82 ms
47,272 KB
testcase_22 AC 79 ms
47,016 KB
testcase_23 AC 138 ms
58,340 KB
testcase_24 AC 98 ms
52,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(input) {
  let [N, K] = getIntegers(input, " ");
  let dp = new Array(10e5).fill(0);
  let A = input.shift().split(" ").map(function(e) {
    let n = Number(e);
    dp[n]++;
    return n;
  });
  
  let count = 0;
  for(let i=0; i<N; i++) {
    let V = K - A[i];
    if(V < 0 || V > 10e5) continue; 
    count += dp[V];
  }
  console.log(count);
}

//-- functions ------------------------------------

function getIntegers(lines, sep) {
  if(sep === undefined) {
    return lines.map(function(e) {
      return Number(e);
    });  
  } else {
    return lines.shift().split(sep).map(function(e) {
      return Number(e);
    });  
  }
}

function getBigIntegers(lines, sep=" ") {
  return lines.shift().split(sep).map(function(e) {
    return BigInt(e);
  });
}

function getStrings(lines, sep=" ") {
  return lines.shift().split(sep);
}

function twoDimenArrayByValue(h, w, value) {
  const list = new Array(h);
  for(let i=0; i<h; i++) {
    list[i] = new Array(w).fill().map(function(e) {
      return value.constructor == Array ? Array.from(value) : value;
    });
  }
  return list;
}

function twoDimenArrayByStrings(h, strings) {
  const list = new Array(h);
  for(let i=0; i<h; i++) {
    list[i] = strings.shift().split("");
  }
  return list;
}

function distance(x1, y1, x2, y2) {
  return Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
}

function gcd(a, b) {
  return b === 0 ? a : gcd(b, a % b);
}

const lower_bound = (arr, val, first = 0, last = arr.length) => {
    first -= 1; // 一番端の位置からさらにずらす
    while (last - first > 1) {
        const mid = first + Math.floor((last - first) / 2);
        if (arr[mid] < val)
            first = mid;
        else
            last = mid;
    }
    return last;
}

const upper_bound = (arr, val, first = 0, last = arr.length) => {
    first -= 1;
    while (last - first > 1) {
        const mid = first - Math.floor((last - first) / 2);
        if (arr[mid] <= val) // ココを直すだけ
            first = mid;
        else
            last = mid;
    }
    return last;
}

//-- Array -------------------------------------------

Array.prototype.deepCopy = function(list) {
  let retList = [];
  for(let i=0; i<list.length; i++) {
    retList[i] = list[i].constructor == Array ? Array.from(list[i]) : list[i];
  }
  return retList;
};

Array.prototype.out = function() {
  let outList = [];
  if(this[0].constructor == Array) {
    for(let i=0; i<this.length; i++) {
      outList.push(this[i].join(" "));
    } 
  } else {
    outList.push(this.join(" "));
  }
  console.log(outList.join("\n"));
};

Array.prototype.pushNoSameValue = function(...values) {
  values.forEach(function(e) {
    if(!this.includes(e)) {
      this.push(e);
    }
  }, this);
};

Array.prototype.sortByIntegers = function() {
  this.sort(function(a, b) {
    return a - b;
  });
};

main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));
0