#P17142. [NOI 2026] 布丁
[NOI 2026] 布丁
Background
The statement and sample attachments are from QOJ。
When submitting to Luogu, there is no need to include the header #include "pudding.h"。Just copy
void init(int c, int t);
int find_tastiness(int c, int m);
int query_tastiness(std::vector<int> a);
to the beginning of your program, and compile with C++17 or a higher version.
This is an interactive problem.
Problem Description
Both Little and Little really like sweet and soft pudding. After tasting many kinds of pudding, they quantify the tastiness of every pudding as a positive integer not exceeding 。
Little is learning to make pudding. Due to limited skill, she can only make pudding whose tastiness does not exceed a constant 。In one attempt, Little successfully made a piece of pudding with tastiness 。Little wants to taste the pudding made by Little , but she must determine the tastiness of the pudding in the way required by Little 。
Specifically, Little can buy several puddings from the store and give them to Little 。Little will mix in the pudding she made, sort all these puddings in nondecreasing order of tastiness, then compute the sum of the greatest common divisors of all adjacent puddings’ tastiness values, and tell the result to Little 。Finally, she will eat all the puddings that Little bought.
Formally, suppose Little buys puddings with tastiness values 。Let the sorted result of be 。Then Little will tell Little the value of 。
Since both the time cost of going to the store and the economic cost of buying puddings are high, Little hopes to minimize both the number of purchases and the total number of puddings bought. You need to help Little design a buying strategy to determine the tastiness of the pudding made by Little 。
【Implementation Details】
Contestants do not need to, and should not, implement the main function.
Contestants must ensure that the submitted program includes the header pudding.h, i.e., add the following code at the beginning of the program:
#include "pudding.h"
Contestants need to implement the following two functions in the submitted source file pudding.cpp:
void init(int c, int t);
- denote the test point ID and the number of testdata groups, respectively. means this test point is the sample.
- For each test point, this function will be called by the interaction library exactly once when the program starts.
int find_tastiness(int c, int m);
- denote the test point ID and the upper bound of the tastiness of the pudding made by Little , respectively.
- This function should return a positive integer , which is the tastiness of the pudding made by Little 。
- For each test point, this function will be called by the interaction library exactly times.
Contestants can make one query by calling the following function:
int query_tastiness(std::vector<int> a);
- is the sequence of tastiness values of the puddings bought by Little 。You must ensure that is non-empty, and every element is a positive integer not exceeding 。
- This function returns the value told by Little to Little , as described in 【Description】.
- You must ensure that, in each call of
find_tastiness, the number of calls to this function does not exceed , and the total sum of the lengths of over all calls does not exceed 。
In any case, the time required by the interaction library will not exceed seconds, and the memory usage will not exceed 。
The file template_pudding.cpp in this problem directory is the provided sample code. You may refer to it and implement your own code.
Input Format
【Test Program Mode】
You can compile an executable file in this problem directory using the following command:
g++ grader.cpp pudding.cpp -o pudding -O2 -std=c++14 -static
For the compiled executable file pudding:
- The executable reads input from standard input in the following format:
- The first line contains three non-negative integers 。
- The second line contains positive integers, which are the values of for each group of testdata.
- The executable outputs to standard output in the following format:
- If the return values of
find_tastinessare all correct for the calls, then:- The first line is
Correct!。 - The second line is
Max queries used: Q, where is the maximum number of calls toquery_tastinessamong all testdata. - The third line is
Max total puddings queried: S, where is the maximum, among all testdata, of the sum of the lengths of passed toquery_tastiness.
- The first line is
- If at least one call to
find_tastinessreturns an incorrect value, then only one lineWrong answer.is printed.
- If the return values of
- If the parameter passed to
query_tastinessdoes not meet the requirements, or the number of calls exceeds the limit, the executable will output an error message to standard error and return 。 - You can enable the
-vor--verboseoption when running the executable file. In this case, the executable will additionally output:- The return value of each call to
find_tastiness, its correctness, the number of calls toquery_tastiness, and the sum of the lengths of passed to it. - The parameters passed to
query_tastinessfor each call, the computation process, and the return value. - The final score ratio obtained by the program. See the section 【Scoring】 for details.
- The return value of each call to
0 2 197
26 121
Correct!
Max queries used: 2
Max total puddings queried: 5
Hint
【Sample Explanation】
For the first group of testdata, the tastiness of the pudding made by Little is 。Below is one possible interaction process:
- Call
query_tastiness(). Then , so the function returns 。 - Call
query_tastiness(). Then , so the function returns 。 - Return , which is correct.
- The number of calls to
query_tastinessis , and the sum of the lengths of passed toquery_tastinessis 。
【Sample 】
See pudding/pudding2.in and pudding/pudding2.ans in the contestant directory.
This sample satisfies the constraints of test point 。
【Sample 】
See pudding/pudding3.in and pudding/pudding3.ans in the contestant directory.
This sample satisfies the constraints of test point 。
【Sample 】
See pudding/pudding4.in and pudding/pudding4.ans in the contestant directory.
This sample satisfies the constraints of test point 。
【Constraints】
For all testdata:
- ;
- ,。
::cute-table{tuack} | Test point ID | Score | | | Special property | |:-:|:-:|:-:|:-:|:-:| | | | | | None | | | | | | | | | | | | None |
Special property : is a prime number.
【Scoring】
Note:
- Contestants should not obtain internal information from the interaction library by illegal means, such as trying to directly read the value of , or directly interacting with standard input and output streams. Such behavior will be considered cheating.
- The interaction library is non-adaptive, i.e., in each call to
find_tastiness, the value of is already fixed and will not change during the interaction process. - The final judging interaction library is implemented differently from the sample interaction library.
If the return value of
find_tastinessis incorrect, or the parameter passed toquery_tastinessdoes not meet the requirements, then the corresponding test point gets points. Under the above conditions: - For each test point, let be the maximum number of calls to
query_tastinessamong all testdata, let be the maximum, among all testdata, of the sum of the lengths of passed toquery_tastiness, and let be the score of this test point. The program obtains $\left\lfloor f(Q)\cdot g(S)\cdot\mathrm{score}\right\rfloor$ points, where and are computed as follows.
::cute-table{tuack} | | | |:-:|:-:| | | | | | |
::cute-table{tuack} | | | |:-:|:-:| | | | | | | | | | | | |
Translated by ChatGPT 5