結果

問題 No.1072 A Nice XOR Pair
ユーザー Tsukasan_z46Tsukasan_z46
提出日時 2020-06-06 10:26:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 538 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 4,618 ms
コンパイル使用メモリ 215,076 KB
実行使用メモリ 37,884 KB
最終ジャッジ日時 2023-08-24 21:40:41
合計ジャッジ時間 4,941 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 538 ms
37,884 KB
testcase_08 AC 32 ms
4,380 KB
testcase_09 AC 31 ms
4,380 KB
testcase_10 AC 63 ms
4,376 KB
testcase_11 AC 319 ms
18,224 KB
testcase_12 AC 508 ms
34,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

// yukicoder No.1072 A Nice XOR Pair
// 2020.06.06
// mapで管理する

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll N, X; cin >> N >> X;
  map<ll, ll> A;
  map<ll, bool> check;
  set<ll> st;
  REPLL(i, N){
    ll a; cin >> a;
    A[a]++;
    check[a] = true;
    st.emplace(a);
  }
  ll ans = 0;

  if(X == 0){  // X == 0の場合、同じものがナイス・ペアになる
    for(auto i : st){
      if(A[i] > 1){
        ans += (A[i]*(A[i]-1))/2;
      }
    }
    cout << ans << endl;
    return 0;
  }

  for(auto i : st){
    if(check[i]){
      ll tmp = X^i;
      if(A.find(tmp) != A.end()){  // 要素が見つかったら
        ans += A[i]*A[tmp];
        check[i] = false;
        check[tmp] = false;
      }
    }
  }
  cout << ans << endl;
}
0