SelfDescFind
TCO19 SRM 758 · 2019-05-09 · by misof
Problem Statement
The number 31143310 is self-describing because we can read it as the statement "this number contains three '1's, one '4's, three '3's, and one '0'", and that statement correctly describes the whole number.
More formally, a number is called self-describing if it satisfies the following:
- It has an even number of digits. Below, we will label the individual digits a[0], b[0], a[1], b[1], ... from the left to the right.
- The digits b[i] are all distinct.
- For each valid i, the number contains exactly a[i] copies of the digit b[i].
- The number does not contain any other digits, except for those described by the statements mentioned above.
You are given the
Notes
- Watch out for integer overflow.
Constraints
- digits will contain between 1 and 10 elements, inclusive.
- Each element of digits will be between 0 and 9, inclusive.
- The elements of digits will form a strictly increasing sequence.
{1}
Returns: ""
{2}
Returns: "22"
The smallest self-describing number is 22. It contains two '2's, and it says about itself that it contains two '2's.
{0,1,3,4}
Returns: "10143133"
{0,1,2,4,5,6,8,9}
Returns: ""
{0,1,2,3,5,6,8,9}
Returns: "1016181923253251"
{4}
Returns: ""
Note that 4444 is not a valid self-describing number.
Submissions are judged against all 83 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SelfDescFind with a public method string construct(vector<int> digits) · 83 test cases · 2 s / 256 MB per case