Merge Elements
Time limit1sMemory limit1024 MB
Given an array, merge adjacent elements with OR exactly K times, then find the maximum AND of the remaining N-K elements.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Greedy, Dynamic programming, Prefix sum
- Solved
- No attempts yet
Problem
You are given an array of non-negative integers. Perform the following operation times on .
- Choose two adjacent elements that remain in the array, apply bitwise to them, and replace the two elements with the result. In other words, if the current length of the array is , choose an integer and change to . Each operation reduces the length of the array by .
After operations, find the maximum possible value of the bitwise of all remaining elements.
Input
The first line contains and , separated by a space. (; )
The second line contains the elements , separated by spaces. ()
Output
Print the maximum value of the bitwise of the elements that remain after operations.
Hint
Bitwise operators work on each bit separately.
-
The bitwise operation () works on each bit of two numbers. The result bit is only when both bits are , and otherwise.
- For example,
-
The bitwise operation () works on each bit of two numbers. The result bit is only when both bits are , and otherwise.
- For example,