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. (三) 查看USB设备

    目录 查看USB设备 lsusb ll /sys/bus/usb/devices cat /sys/kernel/debug/usb/devices dmesg title: 查看USB设备 date ...

  2. Vim-latex 插件 的安装

    ref:https://www.jianshu.com/p/ddd825064062 Vim-latex 插件 1. 安装 Vim-latex 插件是一个强大的Latex插件, 它的安装方法是: 将下 ...

  3. nginx、php-fpm默认配置与性能–TCP socket还是unix domain socket【转】

    原文地址:https://www.cnxct.com/default-configuration-and-performance-of-nginx-phpfpm-and-tcp-socket-or-u ...

  4. SQL 耗时优化

    Ø  简介 在平常的开发中,我们经常会编写各种各样的 SQL 语句,比如:SQL 查询.存储过程.或者视图查询等.当我们编写的 SQL 语句比较复杂,或者表的数据量比较大,导致查询超时!这时,就要去分 ...

  5. 3DMAX中坐标解析

    World:世界坐标系,又称世界空间.位于各视口左下角的图标,显示了世界坐标系的方向,其坐标原点位于视口中心.该坐标系永远不会变化. Screen:屏幕坐标系,此时将使用活动视口屏幕作为坐标系.在活动 ...

  6. 解决 to_csv('****',encoding='utf-8')生成文件乱码

    今天通过to_csv()方法生成csv文件时,发现打开文件都是乱码,后面通过查找资料发现encoding参数要改为“utf_8_sig”才行,“utf-8”是不行的

  7. C#解压文件,Excel操作

    /// <summary> /// 获取目录下文件路径 /// </summary> /// <param name="path"></p ...

  8. 【题解】魔板—洛谷P1275。

    话说好久没更博了. 最近学了好多知识懒的加进来了. 有幸认识一位大佬. 让我有了继续更博的兴趣. 但这是一个旧的题解. 我在某谷上早就发过的. 拿过来直接用就当回归了吧. 其实这道题有一个特别关键的思 ...

  9. zip4j实现文件压缩与解压缩 & common-compress压缩与解压缩

    有时候需要批量下载文件,所以需要在后台将多个文件压缩之后进行下载. zip4j可以进行目录压缩与文件压缩,同时可以加密压缩. common-compress只压缩文件,没有找到压缩目录的API. 1. ...

  10. [Kubernetes]关于 Kubernetes ,你想要的,都在这儿了

    陆陆续续,关于 Kubernetes 写了有 20+ 篇文章了. 今天这篇文章来一个整合,从实践到理论,可以按需查看(我是按照博客发表时间来排序的,如果后续有想要更新的内容,也会及时更新到这篇文章中) ...