結果

問題 No.723 2つの数の和
ユーザー MSK
提出日時 2018-09-30 14:29:22
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 632 bytes
コンパイル時間 845 ms
コンパイル使用メモリ 64,268 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-12 09:06:19
合計ジャッジ時間 2,153 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
  int N, X;
  cin >> N >> X;
  if(X > 200000){
    cout << 0 << endl;
    return 0;
  }
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];

  }
  vector<long> S(200001, 0);
  for(int i = 0; i < N; S[a[i]]++, i++) {}
  long ans = 0;
  for(int i = 0; i < N; i++){
    if(a[i] > X){
      continue;

    }
    if(a[i] == X - a[i]){
      ans += S[a[i]] * S[a[i]];
      S[a[i]] = 0;

    }else{
      ans += 2 * S[a[i]] * S[X-a[i]];
      S[a[i]] = 0;
      S[X - a[i]] = 0;

    }
  }
  cout << ans << endl;
  return 0;

}
0