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. 状压dp(状态压缩&&dp结合)学习笔记(持续更新)

    嗯,作为一只蒟蒻,今天再次学习了状压dp(学习借鉴的博客) 但是,依旧懵逼·································· 这篇学习笔记是我个人对于状压dp的理解,如果有什么不对的 ...

  2. Web_0002:关于MongoDB的操作

    1,启动moggdb服务端 打开cmd命令窗口进入到MongoDB的安装目录bin文件下: 如:  cd /d F:\Program Files\mongodb\bin   执行如下命令(该命令窗口为 ...

  3. <HTML>页面与互联网

    托管 1.数据传输:托管公司允许你在一定时间内向访问者发送的页面和数据量. 2.备份:公司是否对你的页面定期备份,从而在服务器出现硬件故障时能够恢复. 域名 www.starbuzzcoffee.co ...

  4. [Reinforcement Learning] Value Function Approximation

    为什么需要值函数近似? 之前我们提到过各种计算值函数的方法,比如对于 MDP 已知的问题可以使用 Bellman 期望方程求得值函数:对于 MDP 未知的情况,可以通过 MC 以及 TD 方法来获得值 ...

  5. Python——一个简单的进度条的实现

    import math def process_bar(total_work,work_index,length): times = total_work / length # 长度倍数,用来缩放或扩 ...

  6. ccf 201503-5 最小花费 这题交上去只有10分嗨!求大佬的题解啊

    问题描述 C国共有n个城市.有n-1条双向道路,每条道路连接两个城市,任意两个城市之间能互相到达.小R来到C国旅行,他共规划了m条旅行的路线,第i条旅行路线的起点是si,终点是ti.在旅行过程中,小R ...

  7. java平台学习笔记

    java程序从编写源码开始到程序执行一共有三个阶段,编写期,编译期,运行期. 通常,人们都希望自己的程序更快(不仅仅是执行更快,也有编写更快),因此java在不断更新. java源码先通过javac编 ...

  8. 配置tensorflow和keras时教程及问题总结

    基本参数:(如何基本参数和我的电脑不一致,有可能会出意外的错误) 操作系统:Windows 10,64位 Anaconda版本:Python 3.6版本.关于Anaconda的介绍.安装及使用教程可查 ...

  9. 前端笔记知识点整合之JavaScript(四)关于函数、作用域、闭包那点事

    一.自定义函数function 函数就是功能.方法的封装.函数能够帮我们封装一段程序代码,这一段代码会具备某一项功能,函数在执行时,封装的这一段代码都会执行一次,实现某种功能.而且,函数可以多次调用. ...

  10. HBuilderx中编译sass文件

    安装scss/sass编译插件 工具 -> 插件安装 -> scss/sass编译插件 将sass编译成css 新建scss文件,编写完成后,(右键scss文件 -> 外部命令/插件 ...