結果

問題 No.1072 A Nice XOR Pair
ユーザー milanis48663220milanis48663220
提出日時 2020-06-05 21:38:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 164 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 91,048 KB
実行使用メモリ 24,064 KB
最終ジャッジ日時 2024-05-09 20:22:38
合計ジャッジ時間 2,012 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 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 139 ms
16,000 KB
testcase_08 AC 22 ms
5,376 KB
testcase_09 AC 22 ms
5,376 KB
testcase_10 AC 39 ms
5,376 KB
testcase_11 AC 99 ms
10,880 KB
testcase_12 AC 164 ms
24,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, X;
ll ans;
map<int, ll> mp;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> X;
    for(int i = 0; i < N; i++){
        int a;
        cin >> a;
        if(mp.count(a) == 0){
            mp[a] = 1;
        }else{
            mp[a]++;
        }
    }
    for(auto i : mp){
        int a = i.first;
        ll c = i.second;
        if(a == (a^X)) {
            ans += c*(c-1);
        }else {
            ans += c*mp[a^X];   
        }
    }
    cout << ans/2 << endl;
}
0