#P3646. [APIO2015] 巴厘岛的雕塑
[APIO2015] 巴厘岛的雕塑
Description
There are many sculptures along the highways of Bali, Indonesia; we focus on one main road.
There are sculptures on this road. For convenience, we number them continuously from to , and the age of the -th sculpture is years. To make the environment of this road more beautiful, the government wants to divide these sculptures into several groups and plant some trees between groups to attract more tourists to Bali.
The rules for grouping the sculptures are as follows:
The sculptures must be divided into exactly groups, where . Each group must contain at least one sculpture, and each sculpture must belong to exactly one group. All sculptures within the same group must occupy a contiguous segment along the road.
After the sculptures are grouped, for each group we first compute the sum of ages of all sculptures in that group.
Then we compute the bitwise OR of all these sums. We call this value the final aesthetic value of the grouping.
What is the minimum possible final aesthetic value the government can obtain?
Note: The bitwise OR of two nonnegative numbers and is computed as follows:
First convert and to binary.
Let be the number of binary digits of , be that of , and be the maximum of and . The binary representation of is , and that of is , where and are the -th bits in the binary representations of and , respectively. The -th bit is the most significant bit, and the -th bit is the least significant bit.
The result of bitwise OR of and is: $(p_{M-1}\mathbin{\mathrm{OR}} q_{M-1})(p_{M-2}\mathbin{\mathrm{OR}}q_{M-2})\dots (p_1\mathbin{\mathrm{OR}} q_1) (p_0\mathbin{\mathrm{OR}}q_0)$. Where:
.
Input Format
The first line contains three integers separated by spaces.
The second line contains integers separated by spaces.
Output Format
Output a single line with one number, the minimum possible final aesthetic value.
6 1 3
8 1 2 1 5 4
11
Hint
Sample Explanation:
Divide the sculptures into groups, and . Their sums are and , and the final aesthetic value is . (It is not hard to verify that this is also the minimum final aesthetic value.)
Constraints:
Subtask 1 (9 points) ; ; .
Subtask 2 (16 points) ; ; .
Subtask 3 (21 points) ; ; ; .
Subtask 4 (25 points) ; ; .
Subtask 5 (29 points) ; ; ; .
Translated by ChatGPT 5
京公网安备 11011102002149号