#P10512. 序列合并
序列合并
Problem Description
Given a non-negative integer sequence of length , you can perform operations. In each operation, you choose two adjacent numbers and merge them into their bitwise OR.
Formally, in one operation, you choose an index (), and then the original sequence becomes $\{a_1,a_2,\cdots,a_i \operatorname{or} a_{i+1},a_{i+2},\cdots,a_n\}$.
Find the maximum possible value of the bitwise AND of all numbers after operations.
Input Format
The first line contains two positive integers .
The second line contains non-negative integers, where the -th non-negative integer is .
Output Format
Output one line containing one positive integer, which is the answer.
5 2
2 1 2 3 1
2
Hint
[Sample Explanation]
One valid plan:
- In the first operation, merge the first and second numbers, and the sequence becomes .
- In the second operation, merge the third and fourth numbers, and the sequence becomes .
The final bitwise AND of all numbers is . It can be proven that there is no better plan.
[Constraints]
- For of the testdata, .
- For another of the testdata, .
For all testdata, it is guaranteed that , .
Translated by ChatGPT 5