#P10538. [APIO2024] 星际列车

    ID: 12003 远端评测题 1000ms 1000MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2024APIO交互题动态规划优化

[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 NN planets reachable by humans, numbered from 00 to N1N - 1, and MM different interstellar train routes. The ii-th train route (0i<M0 \le i < M) departs from planet X[i]X[i] at time A[i]A[i], arrives at planet Y[i]Y[i] at time B[i]B[i], and costs C[i]C[i]. 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 q[0],q[1],,q[P]q[0], q[1], \ldots, q[P] in order if and only if for every 1kP1 \le k \le P we have Y[q[k1]]=X[q[k]]Y[q[k - 1]] = X[q[k]] and B[q[k1]]A[q[k]]B[q[k - 1]] \le A[q[k]].

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 ii-th interstellar train, then at any moment between A[i]A[i] and B[i]B[i] (including endpoints) you may eat any number of meals for free. However, if you decide to eat on planet ii, each meal costs T[i]T[i].

During the trip, you and your family need to eat a total of WW meals. The ii-th meal (0i<W)(0 \le i < W) can be eaten at any time between L[i]L[i] and R[i]R[i] (including endpoints), and eating takes no time. There is no required order for meals; for example, it is allowed to eat meal 11 before meal 00 (see sample 22).

It is now time 00, and you and your family are on planet 00. You need to find the minimum total cost to reach planet N1N - 1, where the cost is defined as the sum of ticket costs and meal costs. If it is impossible to reach planet N1N - 1, the minimum cost is defined as 1-1.

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);
  • NN: the number of planets.
  • MM: the number of interstellar train routes.
  • WW: the number of meals that must be eaten.
  • TT: an array of length NN. T[i]T[i] is the cost of each meal on planet ii.
  • X,Y,A,B,CX, Y, A, B, C: five arrays of length MM. (X[i],Y[i],A[i],B[i],C[i])(X[i], Y[i], A[i], B[i], C[i]) describes the ii-th train route.
  • L,RL, R: two arrays of length WW. (L[i],R[i])(L[i], R[i]) describes the time window of the ii-th meal.
  • You should return the minimum total cost to reach planet N1N - 1 from planet 00. If planet N1N - 1 is unreachable, return 1-1.
  • In each test case, this function is called exactly once.

Input Format

The sample grader reads input in the following format:

  • Line 11: N M WN\ M\ W
  • Line 22: T[0] T[1] T[2]  T[N1]T[0]\ T[1]\ T[2]\ \ldots\ T[N - 1]
  • Line 3+i (0i<M)3 + i\ (0 \le i < M): X[i] Y[i] A[i] B[i] C[i]X[i]\ Y[i]\ A[i]\ B[i]\ C[i]
  • Line 3+M+i (0i<W)3 + M + i\ (0 \le i < W): L[i] R[i]L[i]\ R[i]

Output Format

The sample grader prints your answer in the following format:

  • Line 11: 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 0,10, 1 in order, with a total cost of 4545. The detailed process is as follows:

Time Your action Cost
11 Take train 00 and depart from planet 00 1010
1515 Arrive at planet 11
1616 Eat meal 00 on planet 11 3030
2020 Take train 11 and depart from planet 11 55
3030 Arrive at planet 22

A better plan is to take train 22, with a total cost of 4040. The detailed process is as follows:

Time Your action Cost
1818 Take train 22 and depart from planet 00 4040
1919 Eat meal 00 on train 22
4040 Arrive at planet 22

In this plan, eating meal 00 on train 22 at time 1818 is also valid.

Therefore, the function should return 4040.

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 00, with a ticket cost of 3838. Eat meal 11 for free on train 00. Eat meals 0,2,30, 2, 3 on planet 22, costing 33×3=9933 \times 3 = 99. Eat meals 4,54, 5 on planet 00, costing 30×2=6030 \times 2 = 60. The total cost is 38+99+60=19738 + 99 + 60 = 197.

Therefore, the function should return 197197.

Constraints

  • 2N1052 \le N \le 10^5
  • 0M,W1050 \le M, W \le 10^5
  • 0X[i],Y[i]<N,X[i]Y[i]0 \le X[i], Y [i] < N, X[i] \neq Y[i]
  • 1A[i]<B[i]1091 \le A[i] < B[i] \le 10^9
  • 1T[i],C[i]1091 \le T[i], C[i] \le 10^9
  • 1L[i]R[i]1091 \le L[i] \le R[i] \le 10^9

The detailed additional constraints and scores for subtasks are shown in the table below.

Subtask ID Additional Constraints Score
11 N,M,A[i],B[i],L[i],R[i]103,W10N, M, A[i], B[i], L[i], R[i] \le 10^3, W \le 10 55
22 W=0W = 0
33 The time windows of all meals are pairwise disjoint. Formally, for any time zz with 1z1091 \le z \le 10^9, there exists at most one i (0i<W)i\ (0 \le i < W) such that L[i]zR[i]L[i] \le z \le R[i]. 3030
44 No additional constraints. 6060

Translated by ChatGPT 5