Turnpike
TCO07 Round 1A · 2007-03-07 · by dgoodman
Problem Statement
The locations of all the existing plazas are given in a
Constraints
- pikeLength will be between 100 and 1000, inclusive.
- n will be between 1 and 100, inclusive.
- plazas will contain between 0 and 50 elements, inclusive.
- The elements in plazas will be distinct values between 1 and pikeLength-1, inclusive.
- n plus the number of elements in plazas will be less than pikeLength.
1000
1
{300,701,800}
Returns: 300
The new plaza should be placed in the segment between 300 and 701. But the best we can do is to make the longest unserviced segment be of length 300, since the segment from 0 to 300 will still be unserviced.
1000
1
{200,701,800}
Returns: 251
We should place the new plaza in the segment between 200 and 701. We can reduce the longest unserviced segment to 251 by placing it either at 450 or at 451.
800
7
{622,411,201,555,755,82}
Returns: 70
The seven new plazas can be distributed along the turnpike so that the longest unserviced segments are from 201 to a new plaza at 271, from 271 to 341 (also a new plaza), and from 341 to the existing plaza at 411.
700
2
{200,400,600}
Returns: 200
700
3
{200,400,600}
Returns: 100
//int k=699, n=4; int[] p = {200,400,600}; //698 //int k=699, n=4; int[] p = {200,400,600,698}; //697 //int k=699, n=4; int[] p = {200,401,600,698}; //501 //int k=720, n=5; int[] p = {200,401,600,708}; //700 //int k=720, n=5; int[] p = {200,401,600}; //700 //int k=100, n=49; int[] p = {2,4,6,8,10,13,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78,80,82,84,86,88,90,92,94,96,98,99};
Submissions are judged against all 92 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Turnpike with a public method int unserviced(int pikeLength, int n, vector<int> plazas) · 92 test cases · 2 s / 256 MB per case