TCSocks
SRM 207 · 2004-08-10 · by Olexiy
Problem Statement
You will be given a
Your method must plan the route that maximizes your profit. You will start in Glastonbury (city 0) and then visit any number of the cities (not visiting a particular city more than once), before finally returning to Glastonbury. All your competitors start their routes in Glastonbury at the same time as you, and they sell socks along the routes specified in competitors. It takes them the same amount of time to travel between cities as it takes you. Your method should return your maximum possible profit.
Notes
- You must finish your route in city 0.
- You may not visit a city more than once.
Constraints
- money will contain between 1 and 10 elements, inclusive.
- times, money and costs will each have the same number of elements.
- Each element of money will be between 0 and 1000, inclusive.
- The first element of money will be 0.
- Each element of times and costs will contain K single-space delimited integers, where K is the number of elements in times and costs.
- Each integer in costs will be between 0 and 1000, inclusive, and will contain no extra leading zeros.
- Each integer in times will be between 1 and 10, inclusive, and will contain no extra leading zeros.
- The ith integers of the ith elements of times and costs will be 0.
- competitors will contain between 0 and 10 elements, inclusive.
- Each element of competitors will be formatted as a single-space delimited list of 1 or more integers.
- Each integer in each element of competitors will be between 1 and the number of elements in money-1, inclusive.
- None of your competitors will visit any city more than once.
{0, 100, 100, 100}
{"0 50 50 200", "0 0 50 200", "0 10 0 200", "0 0 0 0"}
{"0 1 1 1", "1 0 1 1", "1 1 0 1", "1 1 1 0"}
{}
Returns: 140
You have no competitors. Your best path is 0 -> 2 -> 1 -> 0. You spend 50 + 10 + 0 units, and earn 200 units. So the total income is 140.
{0, 100, 100, 100}
{"0 50 50 200", "0 0 50 200", "0 10 0 200", "0 0 0 0"}
{"0 1 1 1", "1 0 1 1", "1 1 0 1", "1 1 1 0"}
{"3", "2 3 1", "2 1"}
Returns: 50
The same data, but now you have three competitors. These competitors decrease your earnings in city 2, so you just visit city 1, and return back to Glastonbury.
{0, 100, 200}
{"0 20 10", "10 0 20", "20 10 0"}
{"0 1 5", "1 0 1", "1 1 0"}
{"2", "2"}
Returns: 240
Both your competitors want to visit city 2 first. Nevertheless, you can leave them behind, visiting city 1, then city 2, and returing back home.
{0, 40, 40, 40, 40, 40}
{"0 25 25 25 25 25", "25 0 25 25 25 25", "25 25 0 25 25 25",
"25 25 25 0 25 25", "25 25 25 25 0 25", "25 25 25 25 25 0"}
{"0 1 1 1 1 1", "1 0 1 1 1 1", "1 1 0 1 1 1", "1 1 1 0 1 1", "1 1 1 1 0 1", "1 1 1 1 1 0"}
{"1", "2", "3", "4", "5"}
Returns: 0
Here, staying at home is your best choice, because any trip is unprofitable.
{0, 70, 70, 70, 70, 70}
{"0 25 25 25 25 25", "25 0 25 25 25 25", "25 25 0 25 25 25",
"25 25 25 0 25 25", "25 25 25 25 0 25", "25 25 25 25 25 0"}
{"0 1 1 1 1 1", "1 0 1 1 1 1", "1 1 0 1 1 1", "1 1 1 0 1 1", "1 1 1 1 0 1", "1 1 1 1 1 0"}
{"1", "2", "3", "4", "5"}
Returns: 25
The same case, except cities give you bigger income. Visiting just one city is still unprofitable, and visiting any two cities still isn't good idea, but you will profit 25 units for visiting all of them in any order.
Submissions are judged against all 45 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TCSocks with a public method int earnMoney(vector<int> money, vector<string> cost, vector<string> time, vector<string> competitors) · 45 test cases · 2 s / 256 MB per case