-
Notifications
You must be signed in to change notification settings - Fork 0
/
And.java
54 lines (49 loc) · 1.4 KB
/
And.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import java.util.* ;
import java.io.BufferedReader ;
import java.io.InputStreamReader ;
public class And
{
public static void main(String args[]) throws Exception
{
BufferedReader bro = new BufferedReader(new InputStreamReader(System.in)) ;
String[] S = bro.readLine().split(" ") ;
int N = Integer.parseInt(S[0]) ;
int K = Integer.parseInt(S[1]) ;
S = bro.readLine().split(" ") ;
int[] A = new int[N] ;
HashSet<Integer> H1 = new HashSet<Integer>() ;
HashSet<Integer> H2 = new HashSet<Integer>() ;
boolean found = false ;
int ways = -1 ;
for(int i=0;i<N;i++)
{
A[i] = Integer.parseInt(S[i]) ;
if(H1.contains(A[i]))
{
// System.out.println("0") ;
ways = 0 ;
found = true ;
break ;
}
H1.add(A[i]) ;
// H2.add(A[i]&K) ;
if(H2.contains(A[i]&K))
{
ways = 2 ;
}
else H2.add(A[i]&K) ;
}
if(!found)
{
for(int i=0;i<A.length;i++)
{
if((A[i]&K)!=A[i] && H1.contains(A[i]&K))
{
ways = 1 ;
}
}
}
System.out.println(ways) ;
////Input k,A
}
}