結果

問題 No.723 2つの数の和
ユーザー yuppe19 😺
提出日時 2018-08-06 16:10:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 12 ms / 2,000 ms
コード長 467 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 75,212 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-19 18:12:57
合計ジャッジ時間 1,504 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
using i64 = long long;

constexpr int N = int(powl(10, 5)) + 10;

int main(void) {
  int n; i64 x; scanf("%d%lld", &n, &x);
  vector<i64> a(N);
  for(int i=0; i<n; ++i) {
    int v; scanf("%d", &v);
    ++a[v];
  }
  i64 res = 0;
  for(int p=0; p<N; ++p) { // p + q == x
    i64 q = x - p;
    if(0 <= q && q < N) {
      res += a[p] * a[q];
    }
  }
  printf("%lld\n", res);
  return 0;
}
0