CF1013B.And
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an array with n elements _a_1, _a_2, ..., a__n and the number x.
In one operation you can select some i (1 ≤ i ≤ n) and replace element a__i with a__i & 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 a__i = a__j. Determine whether it is possible to achieve and, if possible, the minimal number of operations to apply.
有一个包含 n 个元素 a1,a2,…,an 的数组以及一个数 x。
在一次操作中,你可以选择某个下标 i(满足 1≤i≤n),并将元素 ai 替换为 ai & x,其中 & 表示按位与运算。
你希望在执行若干次操作(可能为零次)后,数组中至少存在两个相等的元素。换言之,应存在至少两个互异的下标 i=j,使得 ai=aj。请判断是否能够达成该目标;若可以,则求出所需执行的最少操作次数。
输入格式
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 a__i (1 ≤ a__i ≤ 100 000), the elements of the array.
第一行包含两个整数 n 和 x(2≤n≤100000,1≤x≤100000),分别表示数组的元素个数以及用于按位与运算的数。
第二行包含 n 个整数 ai(1≤ai≤100000),即数组的元素。
输出格式
Print a single integer denoting the minimal number of operations to do, or -1, if it is impossible.
输出一个整数,表示所需的最少操作次数;如果不可能,则输出 −1。
输入输出样例
输入#1
4 3 1 2 3 7
输出#1
1
输入#2
2 228 1 1
输出#2
0
输入#3
3 7 1 2 3
输出#3
-1
说明/提示
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.
在第一个例子中,可以对数组的最后一个元素应用该操作。这会将 7 替换为 3,因此我们只需一步即可达成目标。
在第二个例子中,数组已经包含两个相等的元素。
在第三个例子中,应用该操作根本不会改变数组,因此无法使任意两个元素相等。
输入解题思路,AI测评打分。不知道怎么写?