#4666. OR Sum
OR Sum
OR Sum
题目描述
There are length- sequences and .
Takahashi may perform the following operation on any number of times (possibly zero):
apply a left cyclic shift to the sequence . In other words, replace with defined by , where denotes the remainder when is divided by .
Takahashi's objective is to maximize , where denotes the bitwise logical sum (bitwise OR) of and . Find the maximum possible .
What is the bitwise logical sum (bitwise OR)?
The logical sum (or the OR operation) is an operation on two one-bit integers ($0$ or $1$) defined by the table below.The bitwise logical sum (bitwise OR) is an operation of applying the logical sum bitwise.
| $x$ | $y$ | $x|y$ |
| $0$ | $0$ | $0$ |
| $0$ | $1$ | $1$ |
| $1$ | $0$ | $1$ |
| $1$ | $1$ | $1$ |
Example
0110 | 0101 = 0111输入格式
The input is given from Standard Input in the following format:
输出格式
Print the maximum possible .
3
0 1 3
0 2 3
8
5
1 6 1 4 3
0 6 4 0 1
23
提示
All values in the input are integers.If Takahashi does not perform the operation, remains , and we have $\displaystyle\sum_{i=0}^{N-1} (A_i|B_i)=(0|0)+(1|2)+(3|3)=0+3+3=6$;
if he performs the operation once, making , we have $\displaystyle\sum_{i=0}^{N-1} (A_i|B_i)=(1|0)+(3|2)+(0|3)=1+3+3=7$; and
if he performs the operation twice, making , we have $\displaystyle\sum_{i=0}^{N-1} (A_i|B_i)=(3|0)+(0|2)+(1|3)=3+2+3=8$.
If he performs the operation three or more times, becomes one of the sequences above, so the maximum possible is , which should be printed.
The value is maximized if he performs the operation three times, making ,
where $\displaystyle\sum_{i=0}^{N-1} (A_i|B_i)=(4|0)+(3|6)+(1|4)+(6|0)+(1|1)=4+7+5+6+1=23$.
标签: AtCoder|abc291G
来源
AtCoder|abc291G