CF1696A.NIT orz!
入门
通过率:0%
时间限制:1.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
NIT, the cleaver, is new in town! Thousands of people line up to orz him. To keep his orzers entertained, NIT decided to let them solve the following problem related to orz. Can you solve this problem too?
You are given a 1-indexed array of n integers, a, and an integer z. You can do the following operation any number (possibly zero) of times:
- Select a positive integer i such that 1≤i≤n. Then, simutaneously set ai to (aiorz) and set z to (aiandz). In other words, let x and y respectively be the current values of ai and z. Then set ai to (xory) and set z to (xandy).
Here or and and denote the bitwise operations OR and AND respectively.
Find the maximum possible value of the maximum value in a after any number (possibly zero) of operations.
NIT(“切刀”)初来乍到!成千上万的人排起长队向他膜拜(orz)。为了不让这些膜拜者感到无聊,NIT 决定让他们解决一个与 orz 相关的问题。你也能解决这个问题吗?
给定一个长度为 n 的、下标从 1 开始的整数数组 a,以及一个整数 z。你可以执行以下操作任意多次(也可以不执行):
- 选择一个正整数 i,满足 1≤i≤n。然后同时将 ai 更新为 (aiorz),并将 z 更新为 (aiandz)。换句话说,设 x 和 y 分别为当前的 ai 和 z 的值,则将 ai 设为 (xory),并将 z 设为 (xandy)。
其中,or 和 and 分别表示按位或(OR)和按位与(AND)运算。
求:在执行任意次数(包括零次)操作后,数组 a 中最大值所能达到的最大可能值。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤100). Description of the test cases follows.
The first line of each test case contains two integers n and z (1≤n≤2000, 0≤z<230).
The second line of each test case contains n integers a1,a2,…,an (0≤ai<230).
It is guaranteed that the sum of n over all test cases does not exceed 104.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤100)。随后是测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 z(1≤n≤2000,0≤z<230)。
每个测试用例的第二行包含 n 个整数 a1、a2、…、an(0≤ai<230)。
保证所有测试用例的 n 之和不超过 104。
输出格式
For each test case, print one integer — the answer to the problem.
对于每个测试用例,输出一个整数——即该问题的答案。
输入输出样例
输入#1
5 2 3 3 4 5 5 0 2 4 6 8 1 9 10 5 7 7 15 30 29 27 3 39548743 10293834 10284344 13635445
输出#1
7 13 11 31 48234367
说明/提示
In the first test case of the sample, one optimal sequence of operations is:
- Do the operation with i=1. Now a1 becomes (3or3)=3 and z becomes (3and3)=3.
- Do the operation with i=2. Now a2 becomes (4or3)=7 and z becomes (4and3)=0.
- Do the operation with i=1. Now a1 becomes (3or0)=3 and z becomes (3and0)=0.
After these operations, the sequence a becomes [3,7], and the maximum value in it is 7. We can prove that the maximum value in a can never exceed 7, so the answer is 7.
In the fourth test case of the sample, one optimal sequence of operations is:
- Do the operation with i=1. Now a1 becomes (7or7)=7 and z becomes (7and7)=7.
- Do the operation with i=3. Now a3 becomes (30or7)=31 and z becomes (30and7)=6.
- Do the operation with i=5. Now a5 becomes (27or6)=31 and z becomes (27and6)=2.
在样例的第一个测试用例中,一种最优的操作序列如下:
- 对 i=1 执行操作。此时 a1 变为 (3or3)=3,且 z 变为 (3and3)=3。
- 对 i=2 执行操作。此时 a2 变为 (4or3)=7,且 z 变为 (4and3)=0。
- 对 i=1 执行操作。此时 a1 变为 (3or0)=3,且 z 变为 (3and0)=0。
经过上述操作后,序列 a 变为 [3,7],其最大值为 7。我们可以证明 a 中的最大值不可能超过 7,因此答案为 7。
在样例的第四个测试用例中,一种最优的操作序列如下:
- 对 i=1 执行操作。此时 a1 变为 (7or7)=7,且 z 变为 (7and7)=7。
- 对 i=3 执行操作。此时 a3 变为 (30or7)=31,且 z 变为 (30and7)=6。
- 对 i=5 执行操作。此时 a5 变为 (27or6)=31,且 z 变为 (27and6)=2。
输入解题思路,AI测评打分。不知道怎么写?