結果

問題 No.1072 A Nice XOR Pair
ユーザー milanis48663220milanis48663220
提出日時 2020-06-05 21:38:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 91,020 KB
実行使用メモリ 24,156 KB
最終ジャッジ日時 2023-08-22 14:39:12
合計ジャッジ時間 2,256 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 167 ms
15,860 KB
testcase_08 AC 25 ms
4,380 KB
testcase_09 AC 23 ms
4,380 KB
testcase_10 AC 45 ms
4,376 KB
testcase_11 AC 118 ms
10,984 KB
testcase_12 AC 192 ms
24,156 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