結果

問題 No.1072 A Nice XOR Pair
ユーザー CELICACELICA
提出日時 2020-08-15 13:45:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 824 bytes
コンパイル時間 2,174 ms
コンパイル使用メモリ 175,484 KB
実行使用メモリ 17,280 KB
最終ジャッジ日時 2024-04-19 01:05:03
合計ジャッジ時間 3,999 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 226 ms
17,280 KB
testcase_08 AC 31 ms
5,376 KB
testcase_09 AC 27 ms
5,376 KB
testcase_10 AC 39 ms
5,376 KB
testcase_11 AC 148 ms
10,112 KB
testcase_12 AC 224 ms
16,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using ll = long long;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,x;
    cin >> n >> x;

    vector<ll> va(n);
    map<ll, ll> m;
    for (auto&& v : va)
    {
        cin >> v;
        ++m[v];
    }

    ll res{ 0 };
    if (x == 0)
    {
        for (const auto& im : m)
        {
            if (im.second > 1)
                res += im.second * (im.second-1) / 2;
        }
    }
    else
    {
        sort(va.begin(), va.end());
        auto result = std::unique(va.begin(), va.end());
        va.erase(result, va.end());

        for (const auto& v : va)
        {
            ll xx = v ^ x;

            if (m.count(xx))
                res += m[xx] * m[v];
        }

        res /= 2;
    }
    cout << res << "\n";

    return 0;
}
0