#P3777. [APIO2017] 考拉的游戏
[APIO2017] 考拉的游戏
Description
Koala has invented a new game and invites you to play. At the start of the game, she places items on the table, numbered from to . Then, she secretly assigns each item an integer weight between and , and no two items are assigned the same weight. The weight of item is . She asks you to determine some properties of the sequence of weights .
To answer her questions, you may ask Koala to play several rounds. In each round, you receive blue stones, and Koala receives red stones. First, you may choose some items and place some (or all) of your stones next to these items. Koala observes your placement, and then similarly places some (or all) of her stones next to some items. If the number of red stones next to an item is strictly greater than the number of blue stones next to it, then Koala can obtain this item. When Koala places her stones, she will always choose a plan that maximizes the total weight of the items she obtains. If there are multiple such plans, she will choose one that obtains the maximum number of items. If there are still multiple plans, she may choose any of them.
Koala is very lazy. If you play too many rounds with her, she will fall asleep. Your task is to determine the required properties of Koala’s sequence using as few rounds as possible.
Task
In this task, you need to implement functions: minValue, maxValue, greaterValue, and allValues.
Each function requires you to determine a different property of the sequence . We strongly recommend that you write your solution based on the template we provide. Note that even if you only want to get points for some subtasks, you must provide an implementation for all four functions (although some function bodies may be empty). Your program is not allowed to read from standard input, write to standard output, or interact with any files.
In each function, parameter N is the number of items in the game, and parameter W is the number of stones that you and Koala have in each round.
minValue(N, W)--- This function should return the index of the item with the minimum weight, i.e. .maxValue(N, W)--- This function should return the index of the item with the maximum weight, i.e. .greaterValue(N, W)--- This function should compare the weights of item and item , and return the index of the item with the larger weight. Specifically, if , it should return , otherwise it should return .allValues(N, W, P)--- This function should determine the entire permutation and store it into the given array . Specifically, should store the weight of item .
In each test case, the interaction library will call one of these functions one or more times. Each function call represents a different task. Which function will be called, and the maximum number of calls, depend on the subtask (see below). You may assume that Koala fixes her sequence before each function call, and that the sequence will not change during a single function call. After one call ends, she may change her sequence before the next call.
The four functions you implement can obtain information about Koala’s sequence by calling the function playRound.
playRound(B, R): ask Koala to play one round.
Array B describes how many blue stones you place next to each item. Specifically, for any , blue stones will be placed next to item . Each must be a non-negative integer, and must not exceed .
The interaction library will store Koala’s response in the array R you provide. Specifically, for any , Koala will place red stones next to item .
Each subtask has a limit on how many times you may call playRound within each game. Note that fewer calls may yield a higher score. (See below for the exact limits and scoring method.)
Hint
Subtasks
Sample testdata: points
Due to special reasons (setting -point test cases is not supported), the sample will not be tested during judging.
- There are “sample testdata” test cases. In each test case, exactly one of the functions is called exactly once. See the “Samples” section below for details of each test case.
In each game, you may call playRound at most times.
Subtask 1: points
- In this subtask, the interaction library will only call
minValue. In each test case, this function will be called at most times. - In each game, you may call
playRoundat most times.
Subtask 2: points
- In this subtask, the interaction library will only call
maxValue. In each test case, this function will be called at most times. - In each game, you may call
playRoundat most times. - In this subtask, the score of a test case depends on the maximum number of times
playRoundis called in any game, denoted . Specifically, your score is:- If , you get points.
- If , you get points.
Subtask 3: points
- In this subtask, the interaction library will only call
greaterValue. In each test case, this function will be called at most times. - In each game, you may call
playRoundat most times. - In this subtask, the score of a test case depends on the maximum number of times
playRoundis called in any game, denoted . Specifically, your score is:- If , you get points.
- If , you get points.
- If , you get points.
- If , you get points.
Subtask 4: points
- In this subtask, the interaction library will only call
allValues. In each test case, this function will be called exactly once. - You may call
playRoundat most times.
Subtask 5: points
- In this subtask, the interaction library will only call
allValues. In each test case, this function will be called exactly once. - You may call
playRoundat most times. - In this subtask, the score of a test case depends on the number of times
playRoundis called, denoted . Specifically, your score is:- If , you get points.
- If , you get points. Here, is the greatest integer not exceeding . For example, if , your solution will get points.
Scoring
- As in traditional problems, your program’s time and memory usage must not exceed the limits. The interaction library’s time and memory usage will also be counted in your total time and memory usage. When estimating this part, you may assume that the interaction library used for judging has the same functions and a similar implementation as the sample interaction library we provide.
- In a test case, if you pass an illegal array B when calling
playRound, or if the total number of calls toplayRoundexceeds the limit, then the score for that test case is . - In any game within a test case, if a function does not correctly answer the required property of Koala’s sequence, then the score for that test case is .
- Both Subtask 4 and Subtask 5 require you to implement
allValues, but they pass different values of when calling it. You can use this difference in your implementation to distinguish between the two subtasks. You can refer to your language’s template for more detailed information. - During the contest, you may submit this problem at most 60 times, and there must be at least 2 minutes between two consecutive submissions.
- Your score for a subtask equals the lowest score among all test cases in that subtask.
How to test your program
Compile with the following command in the terminal:
g++ grader.cpp koala.cpp -o grader -g -Wall --std=c++11
The sample interaction library will read input from standard input in the following format:
The first line contains two integers , where is the type of function called by the interaction library, and is the number of function calls.
Then there are lines. Each line starts with two integers , followed by integers .
The function type corresponding to is shown in the following table:
| Function called | |
|---|---|
minValue |
|
maxValue |
|
greaterValue |
|
allValues |
For each function call, the sample interaction library will output two lines to standard output. The first line is the number of times you called playRound. The second line is the result returned after the function call (for , it outputs the array returned by allValues; for other cases, it outputs the return value of the function).
Samples
Consider the following permutation:
| 0 | 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|---|
| 5 | 3 | 2 | 1 | 6 | 4 |
The table below shows some example calls to playRound and valid feedback from the interaction library for each call (note that a single call to playRound may have multiple possible valid feedbacks).
| Call | Possible feedback from the interaction library | Explanation | |
|---|---|---|---|
| 6 | playRound([0,3,0,2,1,0],R) |
R=[1,1,1,0,2,1] |
Koala obtains items , with total weight . This is one possible plan that maximizes the total weight. |
playRound([1,2,3,1,2,0],R) |
Illegal call | You placed a total of stones, exceeding the limit . | |
| 12 | playRound([0,3,0,2,1,0],R) |
R=[2,3,0,2,3,1] |
You do not have to use all stones, and Koala does not have to use all stones either. |
| 6 | playRound([0,1,0,0,1,0],R) |
R=[1,0,1,1,2,1] |
If Koala has multiple plans that maximize the total weight of obtained items, she will choose the one that lets her obtain the most items. Therefore, R=[1,2,0,0,2,1] is not a legal return value. |
Below are the expected return values for the sample testdata. Note that in the sample testdata, you may call playRound at most times.
| # | Function call by the interaction library | Expected return value | Explanation |
|---|---|---|---|
| 1 | minValue(6,6) |
3 | |
| 2 | maxValue(6,6) |
4 | |
| 3 | greaterValue(6,6) |
0 | |
| 4 | allValues(6,12,P) |
P=[5,3,2,1,6,4] |
Note that allValues has no return value; it stores the correct result into . |
| 5 | Same as above. |
Additional Files
The additional files include the sample input and output, the C++ sample interaction library, and the program template. We recommend that you implement your program based on the template.
Translated by ChatGPT 5
京公网安备 11011102002149号