CF1559A.Mocha and Math

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Mocha is a young girl from high school. She has learned so much interesting knowledge from her teachers, especially her math teacher. Recently, Mocha is learning about binary system and very interested in bitwise operation.

This day, Mocha got a sequence aa of length nn. In each operation, she can select an arbitrary interval [l,r][l, r] and for all values ii (0≤i≤r−l0\leq i \leq r-l), replace al+ia_{l+i} with al+i & ar−ia_{l+i} \,\&\, a_{r-i} at the same time, where &\& denotes the bitwise AND operation. This operation can be performed any number of times.

For example, if n=5n=5, the array is [a1,a2,a3,a4,a5][a_1,a_2,a_3,a_4,a_5], and Mocha selects the interval [2,5][2,5], then the new array is [a1,a2 & a5,a3 & a4,a4 & a3,a5 & a2][a_1,a_2\,\&\, a_5, a_3\,\&\, a_4, a_4\,\&\, a_3, a_5\,\&\, a_2].

Now Mocha wants to minimize the maximum value in the sequence. As her best friend, can you help her to get the answer?

摩卡是一名来自高中的年轻女孩。她从老师那里学到了许多有趣的知识,尤其是她的数学老师。最近,摩卡正在学习二进制系统,并对位运算非常感兴趣。

这一天,摩卡得到了一个长度为 nn 的序列 aa。在每次操作中,她可以任选一个区间 [l,r][l, r],并对所有满足 0≤i≤r−l0\leq i \leq r-l 的 ii,同时将 al+ia_{l+i} 替换为 al+i & ar−ia_{l+i} \,\&\, a_{r-i},其中 &\& 表示按位与运算。该操作可执行任意多次。

例如,若 n=5n=5,数组为 [a1,a2,a3,a4,a5][a_1,a_2,a_3,a_4,a_5],而摩卡选择了区间 [2,5][2,5],则新数组变为 [a1,a2 & a5,a3 & a4,a4 & a3,a5 & a2][a_1,a_2\,\&\, a_5, a_3\,\&\, a_4, a_4\,\&\, a_3, a_5\,\&\, a_2]。

现在,摩卡希望最小化序列中的最大值。作为她最好的朋友,你能帮她求出答案吗?

输入格式

Each test contains multiple test cases.

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases. Each test case consists of two lines.

The first line of each test case contains a single integer nn (1≤n≤1001 \le n \le 100) — the length of the sequence.

The second line of each test case contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (0≤ai≤1090 \le a_i \le 10^9).

每个测试包含多个测试用例。

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100),表示测试用例的数量。每个测试用例由两行组成。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100),表示序列的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(0≤ai≤1090 \le a_i \le 10^9)。

输出格式

For each test case, print one integer — the minimal value of the maximum value in the sequence.

对于每个测试用例,输出一个整数——序列中最大值的最小可能值。

输入输出样例

  • 输入#1

    4
    2
    1 2
    3
    1 1 3
    4
    3 11 3 7
    5
    11 7 15 3 7

    输出#1

    0
    1
    3
    3

说明/提示

In the first test case, Mocha can choose the interval [1,2][1,2], then the sequence becomes [0,0][ 0, 0], where the first element is 1 & 21\,\&\,2, and the second element is 2 & 12\,\&\,1.

In the second test case, Mocha can choose the interval [1,3][1,3], then the sequence becomes [1,1,1][ 1,1,1], where the first element is 1 & 31\,\&\,3, the second element is 1 & 11\,\&\,1, and the third element is 3 & 13\,\&\,1.

在第一个测试用例中,Mocha 可以选择区间 [1,2][1,2],此时序列变为 [0,0][ 0, 0],其中第一个元素为 1 & 21\,\&\,2,第二个元素为 2 & 12\,\&\,1。

在第二个测试用例中,Mocha 可以选择区间 [1,3][1,3],此时序列变为 [1,1,1][ 1,1,1],其中第一个元素为 1 & 31\,\&\,3,第二个元素为 1 & 11\,\&\,1,第三个元素为 3 & 13\,\&\,1。

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

首页