D: Doubleplusgood
https://open.kattis.com/problems/doubleplusgood
Last updated
https://open.kattis.com/problems/doubleplusgood
Last updated
Since there are at most 18 digits in the input, there can be at most 8 plus signs, so the problem is brute-forceable in at most evaluations of the input expression.
To brute force search over all binary strings of length , we increment a counter from to ; the th digit in the binary string is then if and otherwise, where is the bitwise AND function. For a given binary string, we then evaluate the input by using the binary string to decide which symbols to interpret as . Since has higher precedence than , we iterate from left to right, keeping track of the sum of previous concatenated terms and the current number; if the next operation is , we concatenate the next number to the current number, and if the next operation is , then we add the current number to the running sum and reset the current number to . We use a set to keep track of the distinct values that we obtain trying all binary strings. In code: