There is an array with n elements a1, a2, ..., an and the number x.

In one operation you can select some i (1 ≤ i ≤ n) and replace element ai with ai & x, where & denotes the bitwise and operation.

You want the array to have at least two equal elements after applying some operations (possibly, none). In other words, there should be at least two distinct indices i ≠ j such that ai = aj. Determine whether it is possible to achieve and, if possible, the minimal number of operations to apply.

Input

The first line contains integers n and x (2 ≤ n ≤ 100 000, 1 ≤ x ≤ 100 000), number of elements in the array and the number to and with.

The second line contains n integers ai (1 ≤ ai ≤ 100 000), the elements of the array.

Output

Print a single integer denoting the minimal number of operations to do, or -1, if it is impossible.

Examples

Input
4 3
1 2 3 7
Output
1
Input
2 228
1 1
Output
0
Input
3 7
1 2 3
Output
-1

Note

In the first example one can apply the operation to the last element of the array. That replaces 7 with 3, so we achieve the goal in one move.

In the second example the array already has two equal elements.

In the third example applying the operation won't change the array at all, so it is impossible to make some pair of elements equal.

题意:给定一个长度为 n(n≤100000) 的序列 ai(ai≤100000),并给定一个数 x(x≤100000) 。
每一步可以将序列中的一个数与上 x。
求使序列中出现两个相等的数的最小步数。如果不可能则输出 −1。

思路:给出两个数 n 与 x,以及长度为 n 的一个数组 a[n],现在问数组中是否有相同的元素,如果有输出0,如果没有则进行 a[i] & x 操作,然后与原数组相比,如果有相同的元素,就输出1,如果还是没有,就看是否存在一个数操作完后与这个数相等,如果存在就输出2,否则,输出-1。

#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int a[200005],b[200005];
int main()
{
int i,j,k,n,x,s=-1;
cin>>n>>x;
while(n--){
cin>>k;
if(a[k]!=0){
s=0;
}
if(s!=0 && (a[k&x]!=0||b[k]!=0)){
s=1;
}
if(s==-1 && b[k&x]){
s=2;
}
a[k]++;
b[k&x]++;
}
cout<<s<<endl;
return 0;
}

  

CF1013B And的更多相关文章

  1. 【题解】CF1013B And

    题面传送门 解决思路 首先我们可以得出,$ a $ \(\&\) $ x $ \(=\) $ a $ \(\&\) $ x $ \(\&\) $ x $.由此得知,同一个 \( ...

  2. 题解合集 (update on 11.5)

    收录已发布的题解 按发布时间排序. 部分可能与我的其他文章有重复捏 qwq . AtCoder for Chinese: Link ZHOJ: Link 洛谷 \(1\sim 5\) : [题解]CF ...

随机推荐

  1. 局域网配置dnsmasq

    一.安装dnsmasq centos下安装dnsmasq: yum install dnsmasq 二.配置dnsmasq: 1.编辑配置文件/etc/dnsmasq.conf # 配置上行DNS,对 ...

  2. Python:Mac 下 MQTT 服务器 Mosquitto 的配置

    我在Mac电脑上搭建时遇到了一些不同于网上大部分情况的问题,特此分享给可能也有遇到相同情况又找不到解决方法的人. 我的电脑系统:macOS Mojave 10.14.3. paho-mqtt 的安装 ...

  3. Gradle创建项目(IntelliJ IDEA)

    创建Gradle项目 步骤一: 步骤二: 步骤三: 步骤四: 步骤五: 此时, 项目已经建好, 如果是第一次使用, 或者本地没有该版本的Gradle时, 就会触发下载.如图所示. 点击红色方框中标识的 ...

  4. 多项式求导系列——OO Unit1分析和总结

    一.摘要 本文是BUAA OO课程Unit1在课程讲授.三次作业完成.自测和互测时发现的问题,以及倾听别人的思路分享所引起个人的一些思考的总结性博客.本文第二部分介绍三次作业的设计思路,主要以类图的形 ...

  5. 【nginx】配置

    server { listen 80; server_name hocalhost; location / { root /usr/share/nginx/html; index index.html ...

  6. 开发一个项目之ES2015+

    变量的解构赋值 任何部署了 Iterator 的对象都可 for of 循环(数组.Set.Map.某些类似数组的对象(arguments对象.DOM NodeList 对象).Generator 对 ...

  7. python核心编程(多线程编程)

    1.全局解释器锁 2.threading模块 thread类

  8. 通过配置文件新建solr的core

    目录solr-7.5.0\server\solr 1.  新建文件夹 test-core 2. 在文件夹test-core下新建core.properties name=test-core confi ...

  9. vscode 前端插件推荐

    参考链接:https://segmentfault.com/a/1190000011779959?utm_source=tag-newest#articleHeader48

  10. Sql语句基础练习(一)

    1.求1号课成绩大于80分的学生的学号及成绩,并按成绩由高到低列出.(表名:成绩表.字段名:课号,学号,成绩.) SELECT 学号,成绩 FROM 成绩表 WHERE 课号=1 AND 成绩> ...