[Solution] ANDfinity Codeforces Solution | Codeforces Problem Solution 2022
Bit Lightyear, to the ANDfinity and beyond!
After graduating from computer sciences, Vlad has been awarded an array of non-negative integers. As it is natural, he wanted to construct a graph consisting of vertices, numbered . He decided to add an edge between and if and only if , where denotes the bitwise AND operation.
Vlad also wants the graph to be connected, which might not be the case initially. In order to satisfy that, he can do the following two types of operations on the array:
- Choose some element and increment it by .
- Choose some element and decrement it by (possible only if ).
It can be proven that there exists a finite sequence of operations such that the graph will be connected. So, can you please help Vlad find the minimum possible number of operations to do that and also provide the way how to do that?
The first line of each test case contains an integer ().
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print a single integer in the first line — the minimum number of operations. In the second line print the array after a valid sequence of operations that have been done such that the graph from the task becomes connected.
If there are multiple solutions, output any.
No comments:
Post a Comment