CF1365E.Maximum Subsequence Value

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Ridhiman challenged Ashish to find the maximum valued subsequence of an array aa of size nn consisting of positive integers.

The value of a non-empty subsequence of kk elements of aa is defined as ∑2i\sum 2^i over all integers i≥0i \ge 0 such that at least max⁡(1,k−2)\max(1, k - 2) elements of the subsequence have the ii-th bit set in their binary representation (value xx has the ii-th bit set in its binary representation if ⌊x2i⌋mod  2\lfloor \frac{x}{2^i} \rfloor \mod 2 is equal to 11).

Recall that bb is a subsequence of aa, if bb can be obtained by deleting some(possibly zero) elements from aa.

Help Ashish find the maximum value he can get by choosing some subsequence of aa.

里迪曼向阿西什发起挑战,要求他找出一个由 nn 个正整数组成的数组 aa 的最大值子序列。

一个非空子序列(含 kk 个元素)的值定义为:对所有满足条件的整数 i≥0i \ge 0,求和 ∑2i\sum 2^i;其中“条件”是指:该子序列中至少有 max⁡(1,k−2)\max(1, k - 2) 个元素在二进制表示中第 ii 位为 11(即,若某数 xx 满足 ⌊x2i⌋ mod 2=1\left\lfloor \frac{x}{2^i} \right\rfloor \bmod 2 = 1,则称其二进制表示中第 ii 位被置位)。

注意:若数组 bb 可通过从 aa 中删除若干(可能为零)元素得到,则称 bb 是 aa 的一个子序列。

请帮助阿西什找出:通过选择 aa 的某个子序列所能获得的最大值。

输入格式

The first line of the input consists of a single integer nn (1≤n≤500)(1 \le n \le 500) — the size of aa.

The next line consists of nn space-separated integers — the elements of the array (1≤ai≤1018)(1 \le a_i \le 10^{18}).

输入的第一行包含一个整数 nn (1≤n≤500)(1 \le n \le 500) —— 表示数组 aa 的大小。

第二行包含 nn 个以空格分隔的整数 —— 数组的元素 (1≤ai≤1018)(1 \le a_i \le 10^{18})。

输出格式

Print a single integer — the maximum value Ashish can get by choosing some subsequence of aa.

输出一个整数——Ashish 通过选择数组 aa 的某个子序列所能获得的最大值。

输入输出样例

  • 输入#1

    3
    2 1 3

    输出#1

    3
  • 输入#2

    3
    3 1 4

    输出#2

    7
  • 输入#3

    1
    1

    输出#3

    1
  • 输入#4

    4
    7 7 1 1

    输出#4

    7

说明/提示

For the first test case, Ashish can pick the subsequence 2,3{{2, 3}} of size 22. The binary representation of 22 is 10 and that of 33 is 11. Since max⁡(k−2,1)\max(k - 2, 1) is equal to 11, the value of the subsequence is 20+212^0 + 2^1 (both 22 and 33 have 11-st bit set in their binary representation and 33 has 00-th bit set in its binary representation). Note that he could also pick the subsequence 3{{3}} or 2,1,3{{2, 1, 3}}.

For the second test case, Ashish can pick the subsequence 3,4{{3, 4}} with value 77.

For the third test case, Ashish can pick the subsequence 1{{1}} with value 11.

For the fourth test case, Ashish can pick the subsequence 7,7{{7, 7}} with value 77.

对于第一个测试用例,Ashish 可以选择长度为 22 的子序列 {2,3}\{2, 3\}。22 的二进制表示为 10,33 的二进制表示为 11。由于 max⁡(k−2,1)\max(k - 2, 1) 等于 11,该子序列的值为 20+212^0 + 2^1(因为 22 和 33 的二进制表示中第 11 位均为 11,且 33 的二进制表示中第 00 位为 11)。注意,他也可以选择子序列 {3}\{3\} 或 {2,1,3}\{2, 1, 3\}。

对于第二个测试用例,Ashish 可以选择子序列 {3,4}\{3, 4\},其值为 77。

对于第三个测试用例,Ashish 可以选择子序列 {1}\{1\},其值为 11。

对于第四个测试用例,Ashish 可以选择子序列 {7,7}\{7, 7\},其值为 77。

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

首页