結果

問題 No.1072 A Nice XOR Pair
ユーザー yomo3yomo3
提出日時 2020-06-08 22:39:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,007 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 176,212 KB
実行使用メモリ 27,392 KB
最終ジャッジ日時 2023-08-27 05:50:04
合計ジャッジ時間 3,577 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 324 ms
22,064 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 87 ms
4,376 KB
testcase_11 AC 191 ms
13,092 KB
testcase_12 AC 332 ms
27,392 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 += c * (c - 1) / 2;
        } else {
            if (m.count(B) > 0) {
                ans += c * m[B];
            }
        }
        done.insert(A);
        done.insert(B);
    }

    cout << ans << endl;
}
0