DivideJewelry
2016 TCO Regional Wildcard · 2016-03-24 · by cgy4ever
Problem Statement
Ciel and Jiro want to divide the jewelry in a fair way. Each fox must take a non-empty subset of the jewelry. Obviously, the two subsets must be disjoint: each piece of jewelry can only be taken by at most one fox. The total value of jewelry taken by Ciel must be exactly the same as the total value of jewelry taken by Jiro.
If there is no valid solution, return an empty
- res[i]=1 denotes that Ciel should take the piece number i
- res[i]=-1 denotes that Jiro should take the piece number i
- res[i]=0 denotes that piece number i should be left in the box
Constraints
- x will contain between 2 and 1,000 elements, inclusive.
- Each element in x will be between 1 and 1,000,000, inclusive.
{1,2,3}
Returns: {1, 1, -1 }
One fox should take pieces 0 and 1, and the other fox should take piece 2. The total value of jewelry taken by each fox will be 3. You may return either {1, 1, -1} or {-1, -1, 1}.
{1,2}
Returns: { }
It is impossible to divide these two pieces evenly. Note that each fox must take at least one piece of jewelry.
{1,1,2,4,8,16,32}
Returns: {1, -1, 0, 0, 0, 0, 0 }
Here, one easy solution is that one fox takes piece 0 and the other fox takes piece 1. This is a fair division because both pieces have the same value.
{1,2,4,8,16,32}
Returns: { }
{534,260,643,230,450,560,430,210}
Returns: {0, 0, 0, 1, -1, 0, 1, -1 }
Submissions are judged against all 126 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class DivideJewelry with a public method vector<int> divide(vector<int> x) · 126 test cases · 2 s / 256 MB per case