Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef long double ld;
- typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>Set;
- typedef tree<ll,ll,less<ll>,rb_tree_tag,tree_order_statistics_node_update> Map;
- #define pb push_back
- #define mp make_pair
- #define mod 1000000007
- #define fi first
- #define se second
- #define pll pair<ll,ll>
- #define ook order_of_key
- #define findby find_by_order
- #define pii pair<ll,ll>
- #define gcd(a,b) __gcd(a,b)
- #define rep(i,n) for(ll i=0;i<n;i++)
- #define reps(i,a,b) for(ll i=a;i<=b;i++)
- template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
- template<typename X> inline X sqr(const X& a) { return (a * a); }
- const ld EPS = ld(1e-9);
- const ld PI = ld(3.141592653589);
- int n;
- int k;
- map<ll,ll>check;
- class Task
- {
- public:
- void solve(istream& in,ostream& out)
- {
- int c;
- in >> n >> k;
- rep(i,n)
- {
- in >> c;
- check[c] ++;
- }
- ll res = 0;
- if (k!=0)
- {
- rep(i,10003)
- {
- for (int j=i+1;j<10004 ;j++)
- {
- if (__builtin_popcount(i^j) == k)
- {
- res += (ll)(check[i])*(ll)(check[j]);
- }
- }
- }
- }
- else
- {
- for (auto j=check.begin();j!=check.end();j++)
- {
- ll c = (*j).se;
- res += (c)*(c-1)/2;
- }
- }
- out << res << endl;
- }
- };
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- Task solver;
- std::istream& in(std::cin);
- std::ostream& out(std::cout);
- solver.solve(in,out);
- out.flush();
- return 0;
- }
Add Comment
Please, Sign In to add comment