Problems > K-th Smallest XOR Value

K-th Smallest XOR Value

Difficulty: 2200 4000 ms 128 MB

bitwise linear-algebra

Consider all distinct XOR values obtainable from subsets of the array (the empty subset gives 0). Print the K-th smallest distinct value, or −1 if fewer than K exist.

Input: the first line has N and K; the second line has N non-negative integers.

Output: the K-th smallest achievable XOR, or −1.

Constraints:

  • 1 ≤ N ≤ 105
  • 0 ≤ ai < 230

Sample Tests

Input 1
3 3
1 2 3
Output 1
2
Input 2
2 4
1 2
Output 2
3

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.