結果
問題 |
No.1072 A Nice XOR Pair
|
ユーザー |
|
提出日時 | 2020-06-08 22:40:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 420 ms / 2,000 ms |
コード長 | 1,015 bytes |
コンパイル時間 | 2,118 ms |
コンパイル使用メモリ | 177,556 KB |
実行使用メモリ | 27,520 KB |
最終ジャッジ日時 | 2024-12-26 15:39:14 |
合計ジャッジ時間 | 4,519 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 11 |
ソースコード
#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 += (ll)c * (c - 1) / 2; } else { if (m.count(B) > 0) { ans += (ll)c * m[B]; } } done.insert(A); done.insert(B); } cout << ans << endl; }