結果

問題 No.1072 A Nice XOR Pair
ユーザー MisterMister
提出日時 2020-08-01 07:27:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 626 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 82,428 KB
実行使用メモリ 15,876 KB
最終ジャッジ日時 2023-09-21 19:05:11
合計ジャッジ時間 3,373 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 238 ms
15,876 KB
testcase_08 AC 25 ms
4,376 KB
testcase_09 AC 24 ms
4,376 KB
testcase_10 AC 49 ms
4,376 KB
testcase_11 AC 136 ms
8,936 KB
testcase_12 AC 213 ms
14,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <map>

using lint = long long;

void solve() {
    int n, x;
    std::cin >> n >> x;

    std::map<int, lint> cnt;
    while (n--) {
        int a;
        std::cin >> a;

        if (!cnt.count(a)) cnt[a] = 0;
        ++cnt[a];
    }

    lint ans = 0;
    for (auto [a, c] : cnt) {
        if (x == 0) {
            ans += c * (c - 1);
        } else {
            auto b = (a ^ x);
            if (cnt.count(b)) ans += c * cnt[b];
        }
    }

    std::cout << ans / 2 << "\n";
}

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

    solve();

    return 0;
}
0