#P10786. [NOI2024] 百万富翁
[NOI2024] 百万富翁
Background
This problem only supports judging in C++. Due to platform limits, submitting with C++14 (GCC 9) will cause CE. Please submit using other C++ versions (C++14 or later is recommended).
Different from NOI’s required submission format, your program should not include the header file richest.h. Also, on the premise that your program includes the vector header, it should declare the following function:
std::vector<int> ask(std::vector<int> a, std::vector<int> b);
Other requirements are the same as NOI’s requirements.
Problem Description
Xiao Y’s bank has clients, numbered from to . Client has a deposit of yuan, and all clients’ deposit amounts are pairwise distinct.
Xiao P is Xiao Y’s close partner, and he wants to know which client has the most deposit. Xiao P cannot directly obtain the deposit amounts, but he can send several requests one by one. Each request contains several queries. Each query is an ordered pair , meaning that Xiao P wants to know which of client and client has more deposit. If , Xiao Y answers , otherwise he answers .
Xiao P has upper limits on the number of requests and the total number of queries across all requests . He wants you to write a program to find the client with the largest deposit.
Input Format
You do not need to, and should not, implement the main function.
You should ensure that the submitted program includes the header file richest.h. You may add the following code at the beginning of your program:
#include "richest.h"
You need to implement the following function:
int richest(int N,int T,int S);
- is the number of clients.
- means that, for the current call, the number of requests must not exceed this value.
- means that, for the current call, the total number of queries across all requests must not exceed this value.
- The function should return the index of the client with the largest deposit.
- For each test point, this function will be called by the interactive library exactly times.
You can send one request to the interactive library by calling the following function:
std::vector <int> ask(std::vector <int> a, std::vector <int> b);
- When calling
ask, you must ensure that the lengths of parameters and are the same, and every element in them must be a non-negative integer less than , representing all queries in this request. - The function returns a
std::vector <int>with the same length as and . Denote it by , where is the index of the client with the larger deposit between clients and .
The problem guarantees that under the given limits on requests and queries, the interactive library runs in at most seconds. The interactive library’s memory usage is fixed and does not exceed MiB.
grader.cpp in the problem directory is a reference implementation of the interactive library. The interactive library used in the final tests is different from the reference implementation, so your solution should not rely on how the interactive library is implemented.
You can compile an executable in this problem directory using the following command:
g++ grader.cpp richest.cpp -o richest -O2 -std=c++14 -static
For the compiled executable:
- The executable will read input from standard input in the following format:
- The first line contains four non-negative integers , where is the random seed used by the interactive library to generate testdata.
- After reading the input, the interactive library will call the function
richesttimes, and test it on testdata generated from the input parameters. Afterrichestreturns, the interactive library will output the following information:- In the first output lines, each line first contains three integers , indicating the result of that run. Here is the return value of
richest, and the meanings of and are as described above, followed by messages about correctness, etc. - The -th line contains the overall information of the runs.
- In the first output lines, each line first contains three integers , indicating the result of that run. Here is the return value of
Output Format
Suppose the testdata generated by the executable is , , , . Below is a correct interactive process:
::cute-table{tuack}
| Contestant Program | Interactive Library | Explanation |
|---|---|---|
Call richest(4,100,100) |
Start testing. | |
Call ask([0,2],[1,3]) |
Return | . |
Call ask([0,2,3],[1,1,1]) |
Return | . |
| Finish and return | Print interaction result to the screen. | Interaction ends, and the result is correct. |
In this example, , which satisfies the limits on requests and queries.
Hint
[Files Provided]
In this problem directory:
grader.cppis a reference implementation of the interactive library.richest.his a header file; contestants do not need to care about its contents.template_richest.cppis sample code; contestants may implement their solution based on it.
Please back up all provided files. In the final judging, only richest.cpp in this problem directory will be tested. Modifying files other than this program will not affect the judging result.
[Constraints]
For all testdata, it is guaranteed that all are pairwise distinct.
This problem has test points. The score and constraints for each test point are shown in the table below.
::cute-table{tuack}
| Test Point ID | Score | |||
|---|---|---|---|---|
[Scoring]
Notes:
- Contestants must not obtain internal information from the interactive library by illegal means, such as trying to directly read the values of array , or interacting directly with standard input/output streams. Such behavior will be considered cheating.
- The interactive library used in the final judging is different from the sample interactive library, and may be adaptive: as long as it does not contradict results previously returned by
ask, the final interactive library may dynamically adjust the values of .
This problem is first subject to the same limits as traditional problems. For example, a compile error results in points for the whole problem; runtime errors, exceeding the time limit, or exceeding the memory limit will all result in points for the corresponding test point. Contestants may only access variables or data defined by themselves and provided by the interactive library, as well as their corresponding memory. Attempting to access other memory locations may lead to compile errors or runtime errors.
In each call to richest, the number of requests used and the total number of queries across all requests must be within the corresponding limits; otherwise, you will get points.
Based on the above conditions:
- In test point , you get full score if and only if calls to
askare legal andrichestreturns the correct answer. - In test point , your score will be calculated as follows:
- If any call to
askis illegal, you get points. - If all calls to
askare legal, let be the maximum among the multiple calls torichest, and let be the maximum . Then the program gets points, where and are computed as in the tables below:
- If any call to
::cute-table{tuack}
::cute-table{tuack}
| $\dfrac{2}{3}-\dfrac{1}{1\,500}\sqrt{\max s-1\,100\,043}$ |
Below are examples in test point showing how different and affect the score.
::cute-table{tuack}
| Score for Test Point | ||
|---|---|---|
Translated by ChatGPT 5