#P15246. [WC2026] 猫和老鼠

    ID: 17345 远端评测题 6000ms 1024MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>cdq 分治交互题O2优化费用流2026WC

[WC2026] 猫和老鼠

Background

6s 1G.

When submitting on Luogu, please use a language version no lower than C++17, and you do not need to include the game.h header file.

Problem Description

Tom and Jerry is a well-known cartoon. Based on it, Xiao G designed a game. In this game, the player needs to help Tom use robotic cats to catch Jerry.

Jerry’s activity range is the interval [0,m][0, m] on the number line. At the initial moment (i.e., at second 00), Jerry may be at any position within this interval. After that, it can move freely within this interval, but its speed at any time will not exceed 11 unit length per second.

Tom has nn robotic cats available to deploy. The cost to deploy the ii-th (1≤i≤n1 \le i \le n) robotic cat is wiw_i. If the ii-th (1≤i≤n1 \le i \le n) robotic cat is deployed, it will appear at position aia_i at time tit_i, then move uniformly at a speed of 11 unit length per second toward position bib_i, and disappear after it arrives.

Jerry initially has kk health points. Each time it completely coincides with a robotic cat (i.e., there exists some moment when their positions are exactly the same), its health will decrease by 11, and that robotic cat will also become invalid. When Jerry’s health is less than or equal to 00, Tom successfully catches Jerry.

Xiao G requires Tom to deploy the robotic cats at the initial moment. Therefore, the player needs to choose some robotic cats to deploy before the game starts. The player wins if and only if, after deploying the robotic cats, for all possible movement paths of Jerry, Tom can successfully catch Jerry.

Xiao G designed many levels for this game and invited you to test them. To control the difficulty, Xiao G plans to set a reasonable upper bound on the total deployment cost. You need to help Xiao G find the minimum total cost of robotic cats that must be deployed for the player to win.

【Implementation Details】

Contestants do not need to, and should not, implement the main function.

Contestants need to make sure the submitted program includes the header file game.h, i.e., add the following code at the beginning of the program:

#include "game.h"

In the submitted source file game.cpp, contestants need to implement the following two functions:

void init(int c, int t);
  • c,tc, t denote the test point ID and the number of testdata groups, respectively. c=0c = 0 means this test point is the sample.
  • For each test point, this function will be called by the interactive library exactly once when the program starts running.
long long game(int n, int m, int k, std::vector<int> a, std::vector<int> b, std::vector<int> t, std::vector<int> w);
  • n,m,kn, m, k denote the number of robotic cats, Jerry’s activity range, and Jerry’s initial health points, respectively.
  • For 0≤i<n0 \le i < n, ai,bi,ti,wia_i, b_i, t_i, w_i denote the appearance position, final position, appearance time, and deployment cost of the (i+1)(i+1)-th robotic cat, respectively.
  • This function should return the minimum total cost. In particular, if it is impossible to win even after deploying all robotic cats, return −1-1.
  • For each test point, this function will be called by the interactive library exactly tt times.

Note: In all cases, the time required by the interactive library will not exceed 0.10.1 seconds, and its memory usage is fixed and will not exceed 6464 MiB.

【How to Test with the Provided Program】

grader.cpp under the problem directory is a reference implementation of the interactive library. The interactive library used in the final test is different from this reference implementation, so contestants’ solutions should not rely on the implementation details of the interactive library.

Contestants can compile an executable in this directory using the following command:

g++ grader.cpp game.cpp -o game -O2 -std=c++14 -static

Input Format

For the compiled executable:

  • The executable will read input from standard input in the following format:
    • The first line contains two non-negative integers c,tc, t, denoting the test point ID and the number of testdata groups.
    • Then follow the testdata groups one by one. For each testdata group:
      • The first line contains three positive integers n,m,kn, m, k, denoting the number of robotic cats, Jerry’s activity range, and Jerry’s initial health points.
      • The (i+1)(i+1)-th line (1≤i≤n1 \le i \le n) contains four non-negative integers ai,bi,ti,wia_i, b_i, t_i, w_i, denoting the appearance position, final position, appearance time, and deployment cost of the ii-th robotic cat.

Output Format

  • The executable will output data to standard output in the following format:
    • For each testdata group, output one line with one integer, denoting the minimum total cost. In particular, if it is impossible to win even after deploying all robotic cats, output −1-1.
0 3
4 10 1
0 6 0 1
4 8 6 2
10 2 7 3
0 8 4 4
3 6 2
2 6 0 0
4 0 1 0
5 0 2 0
7 9 2
3 0 1 7
3 6 1 8
6 9 4 9
3 0 7 3
3 6 7 3
3 6 7 5
6 9 10 5
6
-1
35

Hint

【Sample 1 Explanation】

This sample contains three testdata groups.

For the first testdata group, the player can choose to deploy robotic cats 1,2,31, 2, 3, with a total cost of 1+2+3=61 + 2 + 3 = 6. If the player chooses to deploy robotic cats 1,31, 3, then when Jerry is initially at position 77 and moves uniformly from second 66 at a speed of 11 unit length per second to position 11, Tom cannot successfully catch Jerry.

For the second testdata group, when Jerry is initially at position 5.55.5 and does not move, it will only completely coincide with robotic cat 11 at second 3.53.5, so it is impossible to win even after deploying all robotic cats.

For the third testdata group, the player can choose to deploy robotic cats 1,2,3,4,5,71, 2, 3, 4, 5, 7, with a total cost of 7+8+9+3+3+5=357 + 8 + 9 + 3 + 3 + 5 = 35.

【Sample 2】

See game/game2.in and game/game2.ans in the contestant directory.
This sample satisfies the constraints of test points 3,43, 4.

【Sample 3】

See game/game3.in and game/game3.ans in the contestant directory.
This sample satisfies the constraints of test points 5,65, 6.

【Sample 4】

See game/game4.in and game/game4.ans in the contestant directory.
This sample satisfies the constraints of test points 10∼1210 \sim 12.

【Sample 5】

See game/game5.in and game/game5.ans in the contestant directory.
This sample satisfies the constraints of test points 16∼1816 \sim 18.

【Sample 6】

See game/game6.in and game/game6.ans in the contestant directory.
This sample satisfies the constraints of test points 23,2423, 24.

【Sample 7】

See game/game7.in and game/game7.ans in the contestant directory.
This sample satisfies the constraints of test point 2525.

【Description of Provided Files】

In this problem directory:

  1. grader.cpp is the provided reference implementation of the interactive library.
  2. game.h is the header file; contestants do not need to care about the specific content.
  3. template_game.cpp is the provided sample code; contestants may refer to it and implement their own code.

Contestants should back up all provided files properly. In the final evaluation, only game.cpp in this problem directory will be tested; modifications to files other than this program will not affect the evaluation result.

【Constraints】

Let N,SN, S be the sums of nn and nknk over all testdata within a single test point, respectively. For all testdata, we have:

  • 1≤t≤201 \le t \le 20.
  • 1≤n≤5×1041 \le n \le 5 \times 10^4, N≤3×105N \le 3 \times 10^5.
  • 1≤m≤1091 \le m \le 10^9, 1≤k≤101 \le k \le 10, S≤106S \le 10^6.
  • For all 1≤i≤n1 \le i \le n, 0≤ai,bi≤m0 \le a_i, b_i \le m, and 0≤ti,wi≤1090 \le t_i, w_i \le 10^9.

::cute-table{tuack}

Test point ID n≤n \le k≤k \le Special property
1,21, 2 1010 A
3,43, 4 10310^3 11 BC
5,65, 6 5×1045 \times 10^4 ^ CD
7,87, 8 10310^3 1010 C
99 5×1045 \times 10^4 ^ CD
10∼1210 \sim 12 ^ C
13,1413, 14 10310^3 11 None
1515 5×1045 \times 10^4 ^ D
16∼1816 \sim 18 ^ None
19∼2219 \sim 22 8080 1010
23,2423, 24 300300 ^
2525 5×1045 \times 10^4
  • Special property A: m≤10m \le 10, and for all 1≤i≤n1 \le i \le n, ti,wi≤10t_i, w_i \le 10.
  • Special property B: m≤103m \le 10^3, and for all 1≤i≤n1 \le i \le n, ti≤106t_i \le 10^6.
  • Special property C: for all 1≤i≤n1 \le i \le n, wi=0w_i = 0.
  • Special property D: for all 1≤i≤n1 \le i \le n, ai≤bia_i \le b_i.

【Scoring】

Note:

  • Contestants should not obtain internal information of the interactive library by illegal means, such as directly interacting with standard input/output streams. Such behavior will be regarded as cheating.
  • The interactive library used in the final evaluation is different from the sample interactive library.

This problem is first subject to the same limits as traditional problems. For example, a compilation error will cause the entire problem to receive 00 points; runtime error, time limit exceeded, memory limit exceeded, etc. will cause the corresponding test point to receive 00 points. Contestants can only access variables they define and variables provided by the interactive library; attempting to access other address spaces may cause compilation errors or runtime errors.

Based on the above conditions:

  • For each test point, the program gets full score if and only if the returned answer is correct for every call to the game function.

Translated by ChatGPT 5