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. 高可用-mysql安装,双主模式+keepalived

    mysql安装 1.添加用户 groupadd mysql useradd -r -g mysql mysql

  2. 微信小程序版本自动更新弹窗提示

    代码如下: onLaunch () { if (wx.canIUse('getUpdateManager')) { const updateManager = wx.getUpdateManager( ...

  3. [Reinforcement Learning] 动态规划(Planning)

    动态规划 动态规划(Dynamic Programming,简称DP)是一种通过把原问题分解为相对简单的子问题的方式求解复杂问题的方法. 动态规划常常适用于具有如下性质的问题: 具有最优子结构(Opt ...

  4. Luogu P4358 密钥破解 题解报告

    题目传送门 [题目大意] 给定一个正整数N,可以被分解为两个不同的质数p和q,计算出r=(p-1)*(q-1). 然后给出了一个小于r且与r互质的整数e,已知e*d≡1(mod r),求d. 最后给定 ...

  5. andriod webview和h5

    1.WebBrowserActivity extends BaseActivity 2.setContentView(R.layout.activity_web_html); <WebView ...

  6. Jquery笔记和ajax笔记

    Jquery笔记:jQuery是一个JavaScript函数库,专为事件处理设计 1.jQuery的引入 <script text="type/javascript" src ...

  7. Light OJ 1085 - All Possible Increasing Subsequences

    题目 link 给定一个序列, 求出上升子序列的总数. 分析 Dp[i] 表示序列 以 i 结尾的数目. 可知 Dp[i]=∑Dp[x]+1 这是一个前缀和, 用树状数组维护. Code #inclu ...

  8. CodeForces 671C - Ultimate Weirdness of an Array

    题意: 给以一个定义, F(l, r) 的值表示序列 A[1:n]的子序列 A[1....(l-1),(r+1)...n] 之中 任意两个数的最大公约数的最大值. 求 Sum=∑i=1N∑j=1N(F ...

  9. Oracle XMLTYPE数据类型创建及插入

    --1.创建xml表Create TABLE testxml2(id NUMBER,data XMLTYPE); --2.插入数据--1)创建目录 CREATE or replace DIRECTOR ...

  10. 测试highlightjs主题1

    package top.shaoxiu.scheduleTask; import org.springframework.scheduling.annotation.EnableScheduling; ...