RollingDiceDivTwo
SRM 536 · 2011-11-22 · by meret
Problem Statement
Every time all the dice were thrown at once, Byteasar wrote down the numbers of pips visible on each of the topmost faces (in any order). The results of the i-th throw are given in throws[i]; the length of throws[i] is equal to the number of dice and each character of throws[i] denotes the number of pips visible on one of the topmost faces. For example, if throws[3][0]='7', this means that in throw 3 (0-based index) one of the dice showed exactly 7 pips on the top. Please note that the ordering of dice may be different for different throws.
Given the
Notes
- Please note that a die can have as few as one or two faces.
Constraints
- rolls will contain between 1 and 50 elements, inclusive.
- rolls[0] will contain between 1 and 50 characters, inclusive.
- All elements of rolls will contain the same number of characters.
- Each character in each element of rolls will be one of '1'-'9'.
{"137", "364", "115", "724"}
Returns: 14
In the first throw the numbers of pips on the topmost faces of the dice were 1, 3 and 7; in the second throw they were 3, 6 and 4, in the third they were 1, 1 and 5 and in the fourth roll they were 7, 2 and 4. The players may have used dice with 3, 4 and 7 faces, giving a total of 14 faces. No other possible set of dice has less faces in total.
{"1112", "1111", "1211", "1111"}
Returns: 5
The players could have used three dice with one face each and one die with two faces.
{"24412", "56316", "66666", "45625"}
Returns: 30
The players could have used five dice with six faces each.
{"931", "821", "156", "512", "129", "358", "555"}
Returns: 19
{"3", "7", "4", "2", "4"}
Returns: 7
Submissions are judged against all 55 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class RollingDiceDivTwo with a public method int minimumFaces(vector<string> rolls) · 55 test cases · 2 s / 256 MB per case