Bit Operations
Time limit1sMemory limit512 MB
Given N pairs of 8-bit inputs and outputs, build a C expression using x, constants, ~, &, |, ^, +, -, and * that maps each x_i to y_i.
- Level
Medium6 of 10
- Topics
- Bit manipulation, Brute force, Implementation
- Solved
- No attempts yet
Problem
You are given pairs . Construct a function that satisfies for each . The function must be writable in C in the following form:
uint32_t f(uint32_t x) {
return Expression;
}
The Expression must satisfy the following BNF:
<expr> ::= "x"
| <num>
| "(~" <expr> ")"
| "(" <expr> <op2> <expr> ")"
<op2> ::= "&" | "|" | "^" | "+" | "-" | "*"
Here, is an unsigned 32-bit integer written in decimal. It must not have leading zeroes, except that zero is written as .
Input
The first line contains an integer (). The next lines each contain two integers and ().
Output
Print an expression that satisfies the conditions. The output must strictly follow the BNF format above. Extra whitespace, newlines, parentheses, and other characters are not allowed. The output must contain at most characters. The answer is guaranteed to exist for the given input.