CF1625A.Ancient Civilization

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Martian scientists explore Ganymede, one of Jupiter's numerous moons. Recently, they have found ruins of an ancient civilization. The scientists brought to Mars some tablets with writings in a language unknown to science.

They found out that the inhabitants of Ganymede used an alphabet consisting of two letters, and each word was exactly ℓ\ell letters long. So, the scientists decided to write each word of this language as an integer from 00 to 2ℓ−12^{\ell} - 1 inclusively. The first letter of the alphabet corresponds to zero bit in this integer, and the second letter corresponds to one bit.

The same word may have various forms in this language. Then, you need to restore the initial form. The process of doing it is described below.

Denote the distance between two words as the amount of positions, in which these words differ. For example, the distance between 100121001_2 and 110021100_2 (in binary) is equal to two, as these words have different letters in the second and the fourth positions, counting from left to right. Further, denote the distance between words xx and yy as d(x,y)d(x, y).

Let the word have nn forms, the ii-th of which is described with an integer xix_i. All the xix_i are not necessarily different, as two various forms of the word can be written the same. Consider some word yy. Then, closeness of the word yy is equal to the sum of distances to each of the word forms, i. e. the sum d(xi,y)d(x_i, y) over all 1≤i≤n1 \le i \le n.

The initial form is the word yy with minimal possible nearness.

You need to help the scientists and write the program which finds the initial form of the word given all its known forms. Note that the initial form is not necessarily equal to any of the nn given forms.

火星科学家正在探索木星的众多卫星之一——伽尼米德。最近,他们发现了古代文明的遗迹。科学家们将一些刻有未知语言文字的石板带回了火星。

他们发现,伽尼米德居民使用的字母表仅包含两个字母,且每个单词恰好由 ℓ\ell 个字母组成。因此,科学家决定将该语言中的每个单词表示为一个介于 00 到 2ℓ−12^{\ell} - 1(含端点)之间的整数:字母表中的第一个字母对应于该整数的二进制表示中的 0 位,第二个字母对应于 1 位。

同一单词在该语言中可能具有多种不同形式。此时,你需要还原出该单词的初始形式。还原过程如下所述。

定义两个单词之间的距离为它们在对应位置上字母不同的位置数目。例如,100121001_2 与 110021100_2(二进制表示)之间的距离为 2,因为这两个单词从左至右数在第二位和第四位上的字母不同。进一步地,记单词 xx 与 yy 之间的距离为 d(x,y)d(x, y)。

设某单词共有 nn 种形式,其中第 ii 种形式用整数 xix_i 表示。所有 xix_i 不一定互不相同,因为该单词的两种不同形式可能被写成相同的整数。考虑某个单词 yy,则 yy 的“亲近度”(closeness)定义为它到所有已知形式的距离之和,即对所有 1≤i≤n1 \le i \le n 求和 d(xi,y)d(x_i, y)。

初始形式即为使亲近度最小的单词 yy。

你需要帮助科学家编写一个程序,在给定某单词所有已知形式的前提下,找出其初始形式。注意:初始形式不一定等于所给的 nn 个形式中的任意一个。

输入格式

The first line contains an integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. The following are descriptions of the test cases.

The first line contains two integers nn and ℓ\ell (1≤n≤1001 \le n \le 100, 1≤ℓ≤301 \le \ell \le 30) — the amount of word forms, and the number of letters in one word.

The second line contains nn integers xix_i (0≤xi≤2ℓ−10 \le x_i \le 2^\ell - 1) — word forms. The integers are not necessarily different.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。接下来是各测试用例的描述。

第一行包含两个整数 nn 和 ℓ\ell(1≤n≤1001 \le n \le 100,1≤ℓ≤301 \le \ell \le 30)—— 单词变体的数量,以及每个单词的字母数量。

第二行包含 nn 个整数 xix_i(0≤xi≤2ℓ−10 \le x_i \le 2^\ell - 1)—— 单词变体。这些整数不一定互不相同。

输出格式

For each test, print a single integer, the initial form of the word, i. e. such yy (0≤y≤2ℓ−10 \le y \le 2^\ell - 1) that the sum d(xi,y)d(x_i, y) over all 1≤i≤n1 \le i \le n is minimal possible. Note that yy can differ from all the integers xix_i.

If there are multiple ways to restore the initial form, print any.

对于每组测试数据,输出一个整数,即该单词的初始形式,也就是满足对所有 1≤i≤n1 \le i \le n 的 d(xi,y)d(x_i, y) 之和最小的 yy(其中 0≤y≤2ℓ−10 \le y \le 2^\ell - 1)。注意,yy 可以与所有整数 xix_i 均不相同。

若存在多种方式恢复初始形式,输出任意一种即可。

输入输出样例

  • 输入#1

    7
    3 5
    18 9 21
    3 5
    18 18 18
    1 1
    1
    5 30
    1 2 3 4 5
    6 10
    99 35 85 46 78 55
    2 1
    0 1
    8 8
    5 16 42 15 83 65 78 42

    输出#1

    17
    18
    1
    1
    39
    0
    2

说明/提示

In the first test case, the words can be written as x1=100102x_1 = 10010_2, x2=010012x_2 = 01001_2 and x3=101012x_3 = 10101_2 in binary. Let y=100012y = 10001_2. Then, d(x1,y)=2d(x_1, y) = 2 (the difference is in the fourth and the fifth positions), d(x2,y)=2d(x_2, y) = 2 (the difference is in the first and the second positions), d(x3,y)=1d(x_3, y) = 1 (the difference is in the third position). So, the closeness is 2+2+1=52 + 2 + 1 = 5. It can be shown that you cannot achieve smaller closeness.

In the second test case, all the forms are equal to 1818 (10010210010_2 in binary), so the initial form is also 1818. It's easy to see that closeness is equal to zero in this case.

在第一个测试用例中,这些单词的二进制表示分别为 x1=100102x_1 = 10010_2、x2=010012x_2 = 01001_2 和 x3=101012x_3 = 10101_2。令 y=100012y = 10001_2,则 d(x1,y)=2d(x_1, y) = 2(差异位于第四位和第五位),d(x2,y)=2d(x_2, y) = 2(差异位于第一位和第二位),d(x3,y)=1d(x_3, y) = 1(差异位于第三位)。因此,接近度为 2+2+1=52 + 2 + 1 = 5。可以证明,无法获得更小的接近度。

在第二个测试用例中,所有形式均等于 1818(二进制表示为 10010210010_2),因此初始形式也为 1818。显然,此时接近度为 00。

输入解题思路,AI测评打分。不知道怎么写?

首页