#P13231. [GCJ 2015 #3] Log Set
[GCJ 2015 #3] Log Set
题目描述
The power set of a set is the set of all subsets of (including the empty set and itself). It's easy to go from a set to a power set, but in this problem, we'll go in the other direction!
We've started with a set of (not necessarily unique) integers , found its power set, and then replaced every element in the power set with the sum of elements of that element, forming a new set . For example, if , then the power set of is , and so . is allowed to contain duplicates, so if has elements, then always has exactly elements.
Given a description of the elements in and their frequencies, can you determine our original ? It is guaranteed that exists. If there are multiple possible sets that could have produced , we guarantee that our original set was the earliest one of those possibilities. To determine whether a set is earlier than a different set of the same length, sort each set into nondecreasing order and then examine the leftmost position at which the sets differ. is earlier iff the element at that position in is smaller than the element at that position in .
输入格式
The first line of the input gives the number of test cases, . test cases follow. Each consists of one line with an integer , followed by two more lines, each of which has space-separated integers. The first of those lines will have all of the different elements $\mathrm{E}_{1}, \mathrm{E}_{2}, \ldots, \mathrm{E}_{\mathrm{P}}$ that appear in , sorted in ascending order. The second of those lines will have the number of times $\mathrm{F}_{1}, \mathrm{~F}_{2}, \ldots, \mathrm{F}_{\mathrm{P}}$ that each of those values appears in . That is, for any , the element appears times in .
输出格式
For each test case, output one line containing "Case #x: ", where is the test case number (starting from 1), followed by the elements of our original set , separated by spaces, in nondecreasing order. (You will be listing the elements of directly, and not providing two lists of elements and frequencies as we do for .)
5
8
0 1 2 3 4 5 6 7
1 1 1 1 1 1 1 1
4
0 1 2 3
1 3 3 1
4
0 1 3 4
4 4 4 4
3
-1 0 1
1 2 1
5
-2 -1 0 1 2
1 2 2 2 1
Case #1: 1 2 4
Case #2: 1 1 1
Case #3: 0 0 1 3
Case #4: -1 1
Case #5: -2 1 1
提示
Sample Explanation
Note that Cases #4 and #5 are not within the limits for the Small dataset.
In Case #4, is the only possible set that satisfies the conditions. (Its subsets are , and . Those have sums , and , respectively, so has one copy of , two copies of , and one copy of , which matches the specifications in the input.)
For Case #5, note that also produces the same , but is earlier than , since at the first point of difference, . So would not be an acceptable answer. would also be unacceptable, even though it is the correct set, because the elements are not listed in nondecreasing order.
Limits
- .
Small dataset
- Time limit:
2405 seconds. - will contain between 1 and 20 elements.
- each .
Large dataset
- Time limit:
48010 seconds. - will contain between 1 and 60 elements.
- each .