B. And

 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 andoperation.

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.

思路:只有0,1,2,-1几种情况。

#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
    int n,x;
    scanf("%d%d",&n,&x);
    int a[100005];
    int b[100005];
    fill(a,a+100005,0);
    fill(b,b+100005,0);
    for(int i=0;i<n;++i)
    {
        int p,q;
        scanf("%d",&p);
        q=p&x;
        if(p==q) a[p]++;
        else{
            a[p]++;b[q]++;
        }
    }
    for(int i=0;i<100005;++i)
    {
        if(a[i]>=2) { printf("0\n");return 0;}  //如果有一个数的数量超过两个,输出0
    }
    for(int i=0;i<100005;++i)
    {
        if(a[i]==1&&b[i]>=1){printf("1\n");return 0;} //如果有一个数数量为1且至少有一个数可以变到它,输出1
    }
    for(int i=0;i<100005;++i)
    {
        if(b[i]>=2){printf("2\n");return 0;}//如果有两个数能一次变到i,输出2
    }
    printf("-1\n");
    return 0;
}

 

wandb.init是W&B(Weights & Biases)库中的一个函数,用于启动一个新的W&B运行。它需要指定一个项目名称,通过project参数进行设置。使用wandb.init时,你可以选择保存模型的输入和超参数。具体的方法是创建一个config对象,并设置config的属性,如learning_rate。然后在模型训练过程中,可以使用wandb.log来记录度量指标,比如损失值。wandb.log会将这些度量指标随着时间的推移保存下来,以便后续的可视化分析。此外,在wandb.log中也可以使用wandb.Image来保存图像数据。 如果你在wandb.init中没有定义config,你可以使用wandb.config.update方法来更新config的内容。这个方法需要传入一个字典,字典的键值对对应于config的属性和值。 总结起来,wandb.init是启动W&B运行的函数,可以保存模型的输入和超参数。wandb.log用于记录度量指标,并随着时间的推移保存下来。wandb.Image可以用于保存图像数据。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [wandb使用方法以及具体设置](https://blog.csdn.net/weixin_43164054/article/details/124156206)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *2* [Wandb 记录模型训练情况](https://blog.csdn.net/qq_40671063/article/details/127156415)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值