結果

問題 No.1072 A Nice XOR Pair
ユーザー bonKotsubonKotsu
提出日時 2021-06-09 19:18:29
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 599 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 178,068 KB
実行使用メモリ 25,276 KB
最終ジャッジ日時 2023-08-19 03:23:25
合計ジャッジ時間 4,123 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 3 ms
4,388 KB
testcase_07 AC 314 ms
25,276 KB
testcase_08 AC 67 ms
4,380 KB
testcase_09 AC 65 ms
4,380 KB
testcase_10 AC 84 ms
4,384 KB
testcase_11 AC 168 ms
12,772 KB
testcase_12 AC 264 ms
23,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>

int main() {
  int n, x;
  cin >> n >> x;
  set<int> s;
  map<int, ll> mp;


    
  
  rep(i,n) {
    int a;
    cin >> a;
    s.insert(a);
    mp[a]++;
  }
  ll ans = 0;
  if (x == 0) {
    for (auto it : mp) {
      ans += it.second * (it.second-1)/2;
    }
    cout << ans << endl;
    return 0;
  }

  for (int ax : s) {
    auto it = s.find(ax^x);
    if (it != s.end()) {
      ans += mp[ax]*mp[ax^x];
    }
  }
  ans /= 2;
  cout << ans << endl;



}
0