CF1901C.Add, Divide and Floor
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an integer array a1,a2,…,an ( 0≤ai≤109 ). In one operation, you can choose an integer x ( 0≤x≤1018 ) and replace ai with ⌊2ai+x⌋ ( ⌊y⌋ denotes rounding y down to the nearest integer) for all i from 1 to n . Pay attention to the fact that all elements of the array are affected on each operation.
Print the smallest number of operations required to make all elements of the array equal.
If the number of operations is less than or equal to n , then print the chosen x for each operation. If there are multiple answers, print any of them.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of testcases.
The first line of each testcase contains a single integer n ( 1≤n≤2⋅105 ).
The second line contains n integers a1,a2,…,an ( 0≤ai≤109 ).
The sum of n over all testcases doesn't exceed 2⋅105 .
输出格式
For each testcase, print the smallest number of operations required to make all elements of the array equal.
If the number of operations is less than or equal to n , then print the chosen x for each operation in the next line. If there are multiple answers, print any of them.
输入输出样例
输入#1
4 1 10 2 4 6 6 2 1 2 1 2 1 2 0 32
输出#1
0 2 2 5 1 1 6
说明/提示
In the first testcase, all elements are already equal, so 0 operations are required. It doesn't matter if you print an empty line afterwards or not.
In the second testcase, you can't make less than 2 operations. There are multiple answers, let's consider the answer sequence [2,5] . After applying an operation with x=2 , the array becomes [⌊24+2⌋,⌊26+2⌋]=[3,4] . After applying an operation with x=5 after that, the array becomes [⌊23+5⌋,⌊24+5⌋]=[4,4] . Both elements are the same, so we are done.
In the last testcase, you can't make less than 6 operations. Since 6 is greater than n , you don't have to print them. One possible answer sequence is [0,0,0,0,0,0] . We are just dividing the second element by 2 every time and not changing the first element.