CF1763A.Absolute Maximization

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given an array aa of length nn . You can perform the following operation several (possibly, zero) times:

  • Choose ii , jj , bb : Swap the bb -th digit in the binary representation of aia_i and aja_j .

Find the maximum possible value of max(a)min(a)\max(a) - \min(a) .

In a binary representation, bits are numbered from right (least significant) to left (most significant). Consider that there are an infinite number of leading zero bits at the beginning of any binary representation.

For example, swap the 00 -th bit for 4=10024=100_2 and 3=1123=11_2 will result 1012=5101_2=5 and 102=210_2=2 . Swap the 22 -nd bit for 4=10024=100_2 and 3=1123=11_2 will result 0002=02=0000_2=0_2=0 and 1112=7111_2=7 .

Here, max(a)\max(a) denotes the maximum element of array aa and min(a)\min(a) denotes the minimum element of array aa .

The binary representation of xx is xx written in base 22 . For example, 99 and 66 written in base 22 are 10011001 and 110110 , respectively.

输入格式

The first line contains a single integer tt ( 1t1281 \le t \le 128 ) — the number of testcases.

The first line of each test case contains a single integer nn ( 3n5123 \le n \le 512 ) — the length of array aa .

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 0ai<10240 \le a_i < 1024 ) — the elements of array aa .

It's guaranteed that the sum of nn over all testcases does not exceed 512512 .

输出格式

For each testcase, print one integer — the maximum possible value of max(a)min(a)\max(a) - \min(a) .

输入输出样例

  • 输入#1

    4
    3
    1 0 1
    4
    5 5 5 5
    5
    1 2 3 4 5
    7
    20 85 100 41 76 49 36

    输出#1

    1
    0
    7
    125

说明/提示

In the first example, it can be shown that we do not need to perform any operations — the maximum value of max(a)min(a)\max(a) - \min(a) is 10=11 - 0 = 1 .

In the second example, no operation can change the array — the maximum value of max(a)min(a)\max(a) - \min(a) is 55=05 - 5 = 0 .

In the third example, initially a=[1,2,3,4,5]a = [1, 2, 3, 4, 5] , we can perform one operation taking i=2i = 2 , j=5j = 5 , b=1b = 1 . The array now becomes a=[1,0,3,4,7]a = [1, 0, 3, 4, 7] . It can be shown that any further operations do not lead to a better answer — therefore the answer is max(a)min(a)=70=7\max(a) - \min(a) = 7 - 0 = 7 .

首页