結果

問題 No.1072 A Nice XOR Pair
ユーザー chocono2230chocono2230
提出日時 2020-06-05 21:43:14
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 317 ms / 2,000 ms
コード長 894 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 176,032 KB
実行使用メモリ 22,132 KB
最終ジャッジ日時 2023-08-22 14:48:41
合計ジャッジ時間 3,471 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 317 ms
22,132 KB
testcase_08 AC 75 ms
4,376 KB
testcase_09 AC 75 ms
4,376 KB
testcase_10 AC 98 ms
4,380 KB
testcase_11 AC 191 ms
11,452 KB
testcase_12 AC 287 ms
20,340 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, x;
  cin >> n >> x;
  map<int, int> mp;
  map<int, bool> fl;
  rep(i, n){
    int in;
    cin >> in;
    mp[in]++;
    fl[in] = false;
  }
  ll ans = 0;
  for(auto p : mp){
    if(fl[p.first] == true) continue;
    int nx = p.first ^ x;
    if(nx == p.first){
      ans += (ll)p.second * (ll)(p.second - 1) / 2;
    }else if(mp.count(nx) == 1){
      ans += (ll)p.second * (ll)mp[nx];
      fl[nx] = true;
    }
  }
  cout << ans << endl;
  return 0;
}
0