TheJediTest
SRM 569 · 2012-12-13 · by gojira_tc
Problem Statement
To minimize the number of Jedi needed to supervise the test, it was decided to relocate some children. However, to avoid the mess, each child was only allowed to be relocated by at most one floor, i.e. he or she could stay on the same floor, go one floor down or go one floor up. Note that it is not possible to go a floor down from the first floor or a floor up from the last floor.
Determine and return the minimum number of Jedi supervisors needed after the relocation.
Constraints
- students will contain between 1 and 20 elements, inclusive.
- Each element of students will be between 0 and 100,000,000, inclusive.
- K will be between 1 and 100,000,000, inclusive.
{3, 6, 3}
4
Returns: 3
If the children stay the way they are, 4 Jedi will be required. A possible solution with only 3 observers needed is to send all the children to floor 1. Another optimal solution is to send one child from floor 1 to floor 0 and the others to floor 2.
{1, 1, 1, 1}
4
Returns: 2
A single observer can watch four children. However, to gather at the same floor, at least one child would have to move more than one floor away from his or her initial location.
{0, 0, 0, 0}
12345
Returns: 0
For the Jedi Academy, a bad day it was.
{15, 0, 13, 4, 29, 6, 2}
7
Returns: 10
An optimal solution is to gather the children from floor 0 and floor 2 at floor 1, move the children from floor 3 and one child from floor 5 to floor 4 and move the children from the last floor 6 down to floor 5. The quantities of students at each floor will be {0, 28, 0, 0, 34, 7, 0}.
{1284912, 1009228, 9289247, 2157, 2518, 52781, 2, 2818, 68}
114
Returns: 102138
Submissions are judged against all 177 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TheJediTest with a public method int minimumSupervisors(vector<int> students, int K) · 177 test cases · 2 s / 256 MB per case