#P10538. [APIO2024] 星际列车
[APIO2024] 星际列车
Problem Description
Do not submit using C++14 (GCC 9).
In the year 2992, robots have replaced most human work, and everyone has a lot of free time. Therefore, you and your family decide to use this time for an interstellar trip.
There are planets reachable by humans, numbered from to , and different interstellar train routes. The -th train route () departs from planet at time , arrives at planet at time , and costs . Between planets, these interstellar trains are the only means of transportation. For any interstellar train you take, you can only get off at its terminal station, and the departure planet of your next train must be the same as the arrival planet of the previous train (assume transfers take no time). Formally, you can take trains in order if and only if for every we have and .
Traveling between different planets is very time-consuming, so besides ticket costs, meal expenses cannot be ignored. Unlimited food is provided for free on trains, meaning eating on a train costs nothing: if you decide to take the -th interstellar train, then at any moment between and (including endpoints) you may eat any number of meals for free. However, if you decide to eat on planet , each meal costs .
During the trip, you and your family need to eat a total of meals. The -th meal can be eaten at any time between and (including endpoints), and eating takes no time. There is no required order for meals; for example, it is allowed to eat meal before meal (see sample ).
It is now time , and you and your family are on planet . You need to find the minimum total cost to reach planet , where the cost is defined as the sum of ticket costs and meal costs. If it is impossible to reach planet , the minimum cost is defined as .
Implementation Details
You do not need to include the library train.h at the beginning of your program.
You only need to implement the following function:
long long solve(int N, int M, int W, std::vector<int> T,
std::vector<int> X, std::vector<int> Y,
std::vector<int> A, std::vector<int> B, std::vector<int> C,
std::vector<int> L, std::vector<int> R);
- : the number of planets.
- : the number of interstellar train routes.
- : the number of meals that must be eaten.
- : an array of length . is the cost of each meal on planet .
- : five arrays of length . describes the -th train route.
- : two arrays of length . describes the time window of the -th meal.
- You should return the minimum total cost to reach planet from planet . If planet is unreachable, return .
- In each test case, this function is called exactly once.
Input Format
The sample grader reads input in the following format:
- Line :
- Line :
- Line :
- Line :
Output Format
The sample grader prints your answer in the following format:
- Line : the return value of the function
solve.
3 3 1
20 30 40
0 1 1 15 10
1 2 20 30 5
0 2 18 40 40
16 19
40
3 5 6
30 38 33
0 2 12 16 38
1 0 48 50 6
0 1 26 28 23
0 2 6 7 94
1 2 49 54 50
32 36
14 14
42 45
37 40
2 5
4 5
197
Hint
Sample Explanation
For sample 1, consider the following call:
solve(3, 3, 1, {20, 30, 40}, {0, 1, 0}, {1, 2, 2},
{1, 20, 18}, {15, 30, 40}, {10, 5, 40}, {16}, {19});
One feasible plan is to take trains in order, with a total cost of . The detailed process is as follows:
| Time | Your action | Cost |
|---|---|---|
| Take train and depart from planet | ||
| Arrive at planet | ||
| Eat meal on planet | ||
| Take train and depart from planet | ||
| Arrive at planet |
A better plan is to take train , with a total cost of . The detailed process is as follows:
| Time | Your action | Cost |
|---|---|---|
| Take train and depart from planet | ||
| Eat meal on train | ||
| Arrive at planet |
In this plan, eating meal on train at time is also valid.
Therefore, the function should return .
For sample 2, consider the following call:
solve(3, 5, 6, {30, 38, 33}, {0, 1, 0, 0, 1}, {2, 0, 1, 2, 2},
{12, 48, 26, 6, 49}, {16, 50, 28, 7, 54}, {38, 6, 23, 94, 50},
{32, 14, 42, 37, 2, 4}, {36, 14, 45, 40, 5, 5});
The optimal solution is: take train , with a ticket cost of . Eat meal for free on train . Eat meals on planet , costing . Eat meals on planet , costing . The total cost is .
Therefore, the function should return .
Constraints
The detailed additional constraints and scores for subtasks are shown in the table below.
| Subtask ID | Additional Constraints | Score |
|---|---|---|
| The time windows of all meals are pairwise disjoint. Formally, for any time with , there exists at most one such that . | ||
| No additional constraints. |
Translated by ChatGPT 5