#P10258. [COCI 2023/2024 #5] Bitovi
[COCI 2023/2024 #5] Bitovi
Background
Translated from COCI 2023/2024 Contest #5 T2 “Bitovi”.
Problem Description
Which came first, the chicken or the egg? Is it better to live as a millionaire for one hundred years, or spend seven days in poverty? How do you become a chess master? How do you pull up blinds? How do you pass final exams? How do you train a dragon? These are all interesting questions we can think about after the contest, but now we will ask a less interesting computer science question.
You are given two sets of numbers and , both of size . In one operation, you may choose any element from set and change any one bit in its binary representation. The resulting number must not be an element of set before the change.
For example, the binary representation of is . With one operation, it can become , , , or .
Find a sequence of operations that transforms set into set . Two sets are considered equal if they have the same size and there is no element in that does not belong to .
Note: The number of operations does not have to be minimal, but it must satisfy the limits of the task.
Input Format
The first line contains an integer (), the size of sets and .
The second line contains distinct integers (), the elements of set .
The third line contains distinct integers (), the elements of set .
Output Format
On the first line, output the number of operations, not exceeding .
Then output several lines. Each line should contain (), meaning that you change in set into . The binary representations of and must differ in exactly one bit. Also, it must hold that and .
3
0 1 2
1 2 3
2
1 3
0 1
3
4 8 31
0 4 8
5
31 30
30 28
28 24
24 16
16 0
5
0 1 2 4 5
7 6 5 3 2
9
1 3
3 7
0 1
1 0
2 6
0 2
7 3
5 7
4 5
Hint
Sample Explanation 1
If we first perform and then , then between the two operations, set will contain two equal elements, which is not allowed. Another possible solution is , .
Sample Explanation 2
. If we modify bits from the least significant bit to the most significant bit, we can obtain , and in order. After all operations, and are the same.
Subtasks
| Subtask | Points | Constraints |
|---|---|---|
| 1 | 10 | |
| 2 | 15 | |
| 3 | 30 | |
| 4 | 15 | No additional constraints. |
Translated by ChatGPT 5