EllysAndXor
TCO19 Round 1A · 2019-04-15 · by espr1t
Problem Statement
Elly has a sequence of small positive integers. You are given this sequence in the
For this task we will assume that the operations AND and XOR have equal priority (precedence), thus the expression is evaluated left to right. For example, 42 ^ 26 & 38 will be evaluated as (42 ^ 27) & 38 = 49 & 38 = 32. Note, however, that the maximal answer for the numbers (42, 27, 38) is achieved by using the expression 42 & 27 ^ 38 = (42 & 27) ^ 38 = 10 ^ 38 = 44.
Notes
- The result of the bitwise operation AND (denoted as '&') applied on two integers is a new integer, having 1-bits on each position where both integers had a 1 in their binary representation, and 0 on all others. For example, 42(10) & 27(10) = 101010(2) & 011011(2) = 001010(2) = 10(10).
- The result of the bitwise operation XOR (denoted as '^') applied on two integers is a new integer, having 1-bits on each position where exactly one of the integers had a 1 in their binary representation, and 0 on all others. For example, 42(10) ^ 27(10) = 101010(2) ^ 011011(2) = 110001(2) = 49(10).
Constraints
- numbers will contain between 1 and 10 elements, inclusive.
- Each element of numbers will be between 1 and 1000, inclusive.
{42, 27, 38}
Returns: 44
The example from the problem statement.
{666, 133, 438, 123, 893, 674, 462, 209}
Returns: 976
{42}
Returns: 42
The result of an expression with a single number equals the number.
{123, 456, 789, 987, 654, 321}
Returns: 975
{42, 13, 17, 666, 811, 314, 1, 5, 2, 1000}
Returns: 1007
Please note that the answer can go over 1000.
Submissions are judged against all 122 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class EllysAndXor with a public method int getMax(vector<int> numbers) · 122 test cases · 2 s / 256 MB per case