ShortPath
TCCC '04 Semifinals 3 · 2004-02-23 · by dgoodman
Problem Statement
Create a class ShortPath with a method steps that is given
Constraints
- x will have between 2 and 50 elements inclusive.
- y will have the same number of elements as x.
- Each element of x will be between -1,000,000,000 and 1,000,000,000 inclusive.
- Each element of y will be between -1,000,000,000 and 1,000,000,000 inclusive.
- The start and finish points will be distinct from each other and from all other points given by x and y.
{0,2,1}
{0,2,1}
Returns: 3
3 --|--|--|--|--|--|-- 2 --|--|--F--|--|--|-- 1 --|--X--|--|--|--|-- 0 --S--|--|--|--|--|-- 0 1 2 3 4 5 In the diagram, S is the start point, F is the finish, and X is forbidden. There are two different paths of length 3, one of which is S to (0,1) to (1,2) to F. The direct path of length 2 is blocked by the forbidden point.
{0,1,2,2}
{0,1,2,2}
Returns: 1
Take a single diagonal step from (0,0) to (1,1). The second appearance of (2,2) on the forbidden list is legal but never matters.
{1,100000,0,0,0,2,2,2,1,1}
{1,200000,0,1,2,0,1,2,0,2}
Returns: -1
The start point is trapped in a square of forbidden points.
{1,100000,0,0,0,2,2,2,1}
{1,200000,0,1,2,0,1,2,0}
Returns: 199999
{-1000000000,1000000000,-1,0,1,2}
{-1000000000,1000000000,0,0,0,0}
Returns: 2000000002
Submissions are judged against all 38 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class ShortPath with a public method int steps(vector<int> x, vector<int> y) · 38 test cases · 2 s / 256 MB per case