#abc252h. Ex - K-th beautiful Necklace

Ex - K-th beautiful Necklace

Score : 600600 points

问题描述

我们有 NN 颗宝石。第 ii 颗宝石的颜色和美丽度分别为 DiD_iViV_i

这里的每颗宝石颜色均为 1,2,,C1, 2, \ldots, C 中的一种,并且每种颜色至少有一颗宝石。

NN 颗宝石中,我们将选择 CC 颗颜色各不相同的宝石来制作一条项链。(顺序无关紧要。)项链的美观度将为所选宝石的按位异或值。

在所有可能的项链制作方式中,找出具有第 KK 大美观度的项链的美观度。 (如果有多种方式具有相同的美观度,我们将全部计算在内。)

什么是按位异或?

整数 AABB 的按位异或(bitwise XOR),记作 ABA \oplus B,定义如下:

  • ABA \oplus B 用二进制表示时,在 2k2^k 位(k0k \geq 0)上的数字是 11,如果 AABB 中恰好有一个在 2k2^k 位上为 11,否则为 00

例如,35=63 \oplus 5 = 6。(以二进制表示:011101=110011 \oplus 101 = 110。)

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have NN gemstones. The color and beauty of the ii-th gemstone are DiD_i and ViV_i, respectively.
Here, the color of each gemstone is one of 1,2,,C1, 2, \ldots, C, and there is at least one gemstone of each color.

Out of the NN gemstones, we will choose CC with distinct colors and use them to make a necklace. (The order does not matter.) The beautifulness of the necklace will be the bitwise XOR\rm XOR of the chosen gemstones.

Among all possible ways to make a necklace, find the beautifulness of the necklace made in the way with the KK-th greatest beautifulness. (If there are multiple ways with the same beautifulness, we count all of them.)

What is bitwise XOR\rm XOR?

The bitwise XOR\rm XOR of integers AA and BB, ABA \oplus B, is defined as follows:

  • When ABA \oplus B is written in base two, the digit in the 2k2^k's place (k0k \geq 0) is 11 if either AA or BB, but not both, has 11 in the 2k2^k's place, and 00 otherwise.

For example, 35=63 \oplus 5 = 6. (In base two: 011101=110011 \oplus 101 = 110.)

Constraints

  • 1CN701 \leq C \leq N \leq 70
  • 1DiC1 \leq D_i \leq C
  • 0Vi<2600 \leq V_i < 2^{60}
  • 1K10181 \leq K \leq 10^{18}
  • There are at least KK ways to make a necklace.
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN CC KK

D1D_1 V1V_1

\vdots

DND_N VNV_N

Output

Print the answer.

Sample Input 1

4 2 3
2 4
2 6
1 2
1 3

Sample Output 1

5

There are four ways to make a necklace, as follows.

  • Choose the 11-st and 33-rd gemstones to make a necklace with the beautifulness of 4 XOR 2=64\ {\rm XOR}\ 2 =6.
  • Choose the 11-st and 44-th gemstones to make a necklace with the beautifulness of 4 XOR 3=74\ {\rm XOR}\ 3 =7.
  • Choose the 22-nd and 33-rd gemstones to make a necklace with the beautifulness of 6 XOR 2=46\ {\rm XOR}\ 2 =4.
  • Choose the 22-nd and 44-th gemstones to make a necklace with the beautifulness of 6 XOR 3=56\ {\rm XOR}\ 3 =5.

Thus, the necklace with the 33-rd greatest beautifulness has the beautifulness of 55.

Sample Input 2

3 1 2
1 0
1 0
1 0

Sample Output 2

0

There are three ways to make a necklace, all of which result in the beautifulness of 00.

Sample Input 3

10 3 11
1 414213562373095048
1 732050807568877293
2 236067977499789696
2 449489742783178098
2 645751311064590590
2 828427124746190097
3 162277660168379331
3 316624790355399849
3 464101615137754587
3 605551275463989293

Sample Output 3

766842905529259824

update @ 2024/3/10 10:46:56