結果

問題 No.1072 A Nice XOR Pair
ユーザー yomo3yomo3
提出日時 2020-06-08 22:40:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 1,015 bytes
コンパイル時間 1,657 ms
コンパイル使用メモリ 175,772 KB
実行使用メモリ 27,440 KB
最終ジャッジ日時 2023-08-27 05:52:12
合計ジャッジ時間 3,680 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 316 ms
22,048 KB
testcase_08 AC 73 ms
4,376 KB
testcase_09 AC 74 ms
4,380 KB
testcase_10 AC 85 ms
4,376 KB
testcase_11 AC 170 ms
13,224 KB
testcase_12 AC 309 ms
27,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;
using pii = pair<int, int>; using pll = pair<ll, ll>;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class F, class S> istream& operator >> (istream& s, pair<F, S>& p)
{ s >> p.first >> p.second; return s;}

int main()
{
    int N, X; cin >> N >> X;
    map<int, int> m;
    rep(i, N) {
        int A; cin >> A;
        m[A]++;
    }
    ll ans = 0;
    set<int> done;
    for (const auto& p : m) {
        const int& A = p.first;
        const int& c = p.second;
        if (done.count(A) > 0) continue;
        int B = A^X;
        if (A == B) {
            ans += (ll)c * (c - 1) / 2;
        } else {
            if (m.count(B) > 0) {
                ans += (ll)c * m[B];
            }
        }
        done.insert(A);
        done.insert(B);
    }

    cout << ans << endl;
}
0