D. k-Interesting Pairs Of Integers
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Vasya has the sequence consisting of n integers. Vasya consider the pair of integers x and y k-interesting, if their binary representation differs from each other exactly in k bits. For example, if k = 2, the pair of integers x = 5 and y = 3 is k-interesting, because their binary representation x=101 and y=011 differs exactly in two bits.

Vasya wants to know how many pairs of indexes (i, j) are in his sequence so that i < j and the pair of integers ai and aj is k-interesting. Your task is to help Vasya and determine this number.

Input

The first line contains two integers n and k (2 ≤ n ≤ 105, 0 ≤ k ≤ 14) — the number of integers in Vasya's sequence and the number of bits in which integers in k-interesting pair should differ.

The second line contains the sequence a1, a2, ..., an (0 ≤ ai ≤ 104), which Vasya has.

Output

Print the number of pairs (i, j) so that i < j and the pair of integers ai and aj is k-interesting.

Examples
Input
4 1
0 3 2 1
Output
4
Input
6 0
200 100 100 100 200 200
Output
6
Note

In the first test there are 4 k-interesting pairs:

  • (1, 3),
  • (1, 4),
  • (2, 3),
  • (2, 4).

In the second test k = 0. Consequently, integers in any k-interesting pair should be equal to themselves. Thus, for the second test there are 6 k-interesting pairs:

  • (1, 5),
  • (1, 6),
  • (2, 3),
  • (2, 4),
  • (3, 4),
  • (5, 6).

用的新函数__builtin_popcount(i^j)计算i和j二进制不同的个数 用异或判断

#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=,maxn=+,inf=0x3f3f3f3f; ll sum[maxn];
int main()
{
ll n,k,ans=;
memset(sum,,sizeof(sum));
scanf("%I64d%I64d",&n,&k);
for(int i=;i<n;i++)
{
ll a;
scanf("%I64d",&a);
sum[a]++;
}
if(!k)
{
for(int i=;i<=;i++)
ans+=(sum[i]*(sum[i]-)/);
}
else
{
for(int i=;i<=;i++)
for(int j=;j<i;j++)
if(__builtin_popcount(i^j)==k)
ans+=(sum[i]*sum[j]);
}
printf("%I64d\n",ans);
return ;
}
/*
4 1
0 3 2 1
4
*/

codeforce vk cup2017的更多相关文章

  1. VK CUP2017 ROUND 1

    来自FallDream的博客.未经允许,请勿转载,谢谢. ---------------------------------------------------- 和ditoly组队打vkcup,原来 ...

  2. Codeforce - Street Lamps

    Bahosain is walking in a street of N blocks. Each block is either empty or has one lamp. If there is ...

  3. cf.VK CUP 2015.B.Mean Requests

    Mean Requests time limit per test 4 seconds memory limit per test 256 megabytes input standard input ...

  4. DP VK Cup 2012 Qualification Round D. Palindrome pairs

    题目地址:http://blog.csdn.net/shiyuankongbu/article/details/10004443 /* 题意:在i前面找回文子串,在i后面找回文子串相互配对,问有几对 ...

  5. Codeforce Round #216 Div2

    e,还是写一下这次的codeforce吧...庆祝这个月的开始,看自己有能,b到什么样! cf的第二题,脑抽的交了错两次后过了pretest然后system的挂了..脑子里还有自己要挂的感觉,果然回头 ...

  6. VK Cup 2012 Round 3 (Unofficial Div. 2 Edition)

    VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) 代码 VK Cup 2012 Round 3 (Unofficial Div. 2 Edition) A ...

  7. Codeforce 水题报告(2)

    又水了一发Codeforce ,这次继续发发题解顺便给自己PKUSC攒攒人品吧 CodeForces 438C:The Child and Polygon: 描述:给出一个多边形,求三角剖分的方案数( ...

  8. Codeforces Round #409 (rated, Div. 2, based on VK Cup 2017 Round 2)(A.思维题,B.思维题)

    A. Vicious Keyboard time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...

  9. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)爆零记

    昨晚一个瓜皮说今晚有cf,听说是晚间场,我瞅了一眼,娃,VK Cup,上分的好机会,看着比赛时间就有点心酸了,0:35,当时一直在纠结要不要打的问题,当时想着应该不难吧,要不打一下吧,要不还是看看题先 ...

随机推荐

  1. PHP的简单易懂文件管理,可实现基本功能

    我们利用的是嵌入PHP代码和ajax结合的方式,首相想到的是利用遍历文件的方式找出分件下的目录和文件,并且找到它们的路径,使用 dirname取上级目录, basename从完整路径中取文件名,其中最 ...

  2. 关于mui选择器的使用

    使用mui引入选择器的picker.js.poppicker.js.及他们的css文件之后引入代码与点击确定之后的状态: document.querySelector('#osex').addEven ...

  3. keepalived工作原理

    keepalived是一个类似于Layer2,4,7交换机制的软件.是Linux集群管理中保证集群高可用的一个服务软件,其功能是用来防止单点故障.   keepalived的工作原理:         ...

  4. 手动编写JQUERY插件

    就拿一个简单的示例来说,鼠标点击输入框,提示文字消息,鼠标移开,再显示提示文字. <script type="text/javascript"> //编写插件 (fun ...

  5. iOS开发之判断横竖屏切换

    /** *  当屏幕即将旋转的时候调用 * *  @param toInterfaceOrientation 旋转完毕后的最终方向 *  @param duration  旋转动画所花费的时间 */ ...

  6. iOS开发之使程序在后台运行

    方法一(此方法不太可靠): 开启程序后台运行: [application beginBackgroundTaskWithExpirationHandler:^{ //后台运行过期后会调用此block内 ...

  7. shell中的特殊变量和函数传参

    shell中的特殊变量 $? :上一个命令的执行状态返回值 $#::参数的个数 $*:参数列表,所有的变量作为一个字符串 $@:参数列表,每个变量作为单个字符串 $1-9,${10}:位置参数 $$: ...

  8. XML配置文件的命名空间与Spring配置文件中的头

    一直以来,写Spring配置文件,都是把其他配置文件的头拷贝过来,最多改改版本号,也不清楚哪些是需要的,到底是干嘛的.今天整理一下,拒绝再无脑copy. 一.Spring配置文件常见的配置头 < ...

  9. CSS前端开发学习总结、一

    1. 属性选择器: 2. CSS伪类选择器: 3. CSS伪元素: 4. CSS优先级: 5. 行内标签: 6. 块级标签: 7. Display: 8. Line-height:行高 9. text ...

  10. es6编写reactjs事件处理函数绑定this三种方式

    第一种:官方推荐的: class LoginControl extends React.Component { constructor(props) { super(props); this.hand ...