Partitioning
Time limit0.5sMemory limit512 MB
Decide whether the set {0,...,2^N-1} splits into two subsets of sizes K and 2^N-K, each closed under bitwise OR, and print one split if it exists.
- Level
Medium7 of 10
- Topics
- Bit manipulation, Combinatorics, Math, Brute force
- Solved
- No attempts yet
Problem
For a set , call a good set when holds, and only then. Here denotes bitwise-or. For example, is a good set, because , , and are all elements of . However, , so is not a good set.
For a subset of the universe , call an -partition when has elements and both and are good sets, and only then.
Given and , write a program that determines whether an -partition exists and, if it does, prints an example of one.
Input
The first line gives the natural numbers and separated by a space.
Output
If no -partition exists, print NO on the first line.
If an -partition exists, print YES on the first line. On the second line, print the elements of an -partition in increasing order.
If multiple -partitions exist, printing any one of them is accepted.
Constraints
Every input satisfies the following conditions.