Codeforces Round #500 (Div. 2) 2.B

B. And

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

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

Copy

4 3
1 2 3 7

output

Copy

1

input

Copy

2 228
1 1

output

Copy

0

input

Copy

3 7
1 2 3

output

Copy

-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个数 和一个x 问你 是否有相同的 没有的话 a[i] & x操作完之后 跟原来的数列中 如果有相同的数 的话就输出一,若没有,就看是否有另一个数操作完之后与他相等就输出2,(&运算 不可能超过二 超过之后 再怎么运算都不变) (辣鸡题意)

思路: 将每个输入的数都记录一下 超过两个 直接输出零 再将 操作之后的数全部记录下来,在用原来的数找一下 看操作完之后的数是否有相同的 前提是 自己操作完之后不能和自己是相同的 如果是相同的 数量应该是大于等于2的,  如果还是没有找到,就用这个数操作完之后的数在 第二个序列中找一下 ,如果能找到 就输出2;(比较水的题 )

 

代码:

#include<bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    map<int ,int >f,m;
    for(int i = 0; i <n ;i ++){
        scanf("%d",&a[i]);
        if(f[a[i]]){
            printf("0\n");
            return 0;
        }
        m[a[i]&x]++;
        f[a[i]]++;
       // printf("%d :%d\n",a[i],a[i]&x);
    }
    for(int i = 0; i < n; i++){
        int b = a[i]&x;
        if(b == a[i] && m[a[i]] >1){
            printf("1\n");
            return 0;
        }
        else if(b != a[i]&&m[a[i]]){
            printf("1\n");
            return 0;
        }
    }
    for(int i = 0; i < n;i++){
        if(m[a[i]&x] >= 2){
            printf("2\n");
            return 0;
        }
    }
    printf("-1\n");
    return 0;
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值