시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
2 초 | 512 MB | 50 | 9 | 9 | 50.000% |
Koala has created a new game and she has challenged you! She begins by placing down N items, numbered from 0 to N-1. She then secretly assigns each item i an integer value between 1 and N so that no two items have been assigned the same value. Item has been assigned the value Pi. She has challenged you to identify some properties of the sequence of values P = P0, P1, ..., PN-1.
To do this, you will ask Koala to play a series of rounds. In each round, you are given W blue stones, and Koala is given W red stones. You go first by placing some (or possibly all) of your stones next to some items of your choosing. Koala, seeing your arrangement, responds similarly by placing some (or possibly all) of her stones next to some of the items. Koala then wins all items which have strictly more red stones than blue stones next to them. Koala always distributes her stones so that she maximises the sum of the values of the items that she wins. If there are are multiple ways to do this, she picks a way which maximises the total number of items that she wins. If there are still multiple ways to do this, she picks any of these ways.
Koala is very lazy and will fall asleep if you ask her to play too many rounds. Your task is to identify patterns in Koala's sequence P by playing as few rounds as possible.
In this task, there are four functions for you to implement: minValue, maxValue, greaterValue and allValues. Each function requires you to identify a different property of the sequence P. You are strongly recommended to use the template implementation for your language as a starting point for your solution. Note that even if you are only attempting some of the subtasks, you must still provide an implementation for all four functions (though some of these implementations may be empty). Your program must not read from standard input, write to standard output or interact with any files.
In each function the parameter N is the number of items in the game and the parameter W is the number of stones both you and Koala play with in each round of the game.
minValue(N, W)
--- This function should return the item number i with the minimum value, that is, Pi = 1.maxValue(N, W)
--- This function should return the item number i with the maximum value, that is, Pi = N.greaterValue(N, W)
--- This function should compare the value of items 0 and 1, and return the number of the item which is greater. Specifically, it should return 0 if P0 > P1 and return 1 otherwise.allValues(N, W, P)
--- This function should determine the entire sequence P and place it in the provided array P:specifically, P[i]
should contain the value Pi of item i for all 0 ≤ i ≤ N-1.In each testcase, the grader will call precisely one of these functions one or more times. Each function call is to be treated as a separate game. Which function is called and the maximum number of times it may be called depends on the subtask (see below). You may assume that Koala has fixed her sequence P before each function call, and it will not change throughout the duration of the function. She may then change her sequence before the next function call.
The implementation for each function should call the function playRound
to gain information about Koala's sequence.
playRound(B, R)
--- Ask Koala to play a round with you.
B
describes how many blue stones you place next to each item. Specifically, for all 0 ≤ i ≤ N-1, B[i]
blue stones will be placed next to the item numbered i. Each B[i]
must be a non-negative integer and the sum B[0] + B[1] + ... + B[N-1]
must not exceed W.R
to describe Koala's response. Specifically, for all 0 ≤ i ≤ N-1, Koala will place R[i]
red stones next to the item numbered i.playRound
per game. Please note that using fewer calls than this limit may yield a higher scoring solution (see below).playRound
is called with an invalid array B, or the number of calls to playRound
exceeds the hard limit for any game within a testcase, the entire testcase will be marked as Not Correct, scoring 0.allValues
, with different values of W. You may use this to differentiate the two subtasks in your implementation -- see the template implementation in your language for further details.Consider the following sequence P.
i | 0 | 1 | 2 | 3 | 4 | 5 |
---|---|---|---|---|---|---|
Pi | 5 | 3 | 2 | 1 | 6 | 4 |
Below are a series of example calls made to playRound
, and a valid response by the grader to each (note that there may be more than one valid response for any given call to playRound
).
W | Sample function call | Possible grader response | Explanation |
---|---|---|---|
6 | playRound([0, 3, 0, 2, 1, 0], R) |
R = [1, 1, 1, 0, 2, 1] |
You place three, two and one blue stone(s) next to items 1, 3 and 4, respectively, and no stones next to items 0, 2 and 5. In reply, Koala places a single red stone next to items 0, 1, 2 and 5 and two red stones next to item 4 with no red stones next to item 3. Thus, she wins items 0, 2, 4 and 5 with a total combined value of 5 + 2 + 6 + 4 = 17, which is the maximum possible. |
6 | playRound([1, 2, 3, 1, 2, 0], R) |
Invalid function call. Your program is terminated and marked Not Correct, scoring 0 for this testcase. | You have placed 1 + 2 + 3 + 1 + 2 = 9 > 6 = W stones, which is invalid. |
12 | playRound([1, 2, 3, 1, 2, 0], R) |
R = [2, 3, 0, 2, 3, 1] |
You do not need to place all W of your blue stones, and Koala does not need to place all W of her red stones. |
6 | playRound([0, 1, 0, 0, 1, 0], R) |
R = [1, 0, 1, 1, 2, 1] |
If there are multiple possible responses for Koala that maximise her total value, she chooses one that maximises the total number of items that she wins, hence R = [1, 2, 0, 0, 2, 1] is not a valid response. |
Feedback for each of the functions that the grader calls below (exactly one per testcase) is provided in the given order as "Sample Data" upon submission. You may call playRound
at most 3200 times in each of these 5 testcases.
# | Grader calls | Expected return value | Explanation |
---|---|---|---|
1 | minValue(6, 6) |
3 |
P3 = 1, so item 3 has the minimum value. |
2 | maxValue(6, 6) |
4 |
P4 = 6 = N, so item 4 has the maximum value. |
3 | greaterValue(6, 6) |
0 |
P0 = 5 > 3 = P1, so item 0 has a greater value than item 1. |
4 | allValues(6, 12, P) |
None, P = [5, 3, 2, 1, 6, 4] |
The function allValues has no return value, but instead places the correct values in the given array P . |
5 | allValues(6, 6, P) |
None, P = [5, 3, 2, 1, 6, 4] |
Same as the previous function call. |
The sample grader reads from standard input in the following format:
The integer F determines which function the sample grader will call:
F | Function called |
---|---|
1 | minValue |
2 | maxValue |
3 | greaterValue |
4 | allValues |
The integer G determines how many times the specified function will be called. Each subsequent line describes a game with Koala's sequence.
The sample grader will write two lines to standard output for each function call. The first line contains the number of times playRound
was called.
allValues
;For instance, the fourth testcase in "Sample Data" (which calls allValues
with N = 6 and W = 12) can be described with the following sample input file.
4 1 6 12 5 3 2 1 6 4
minValue
. This function will be called at most 100 times per testcase.playRound
at most 2 times per game.maxValue
. This function will be called at most 100 times per testcase.playRound
at most 13 times per game.playRound
is called among all games in that testcase. Precisely your score will be:
greaterValue
. This function will be called at most 1100 times per testcase.playRound
at most 14 times per game.allValues
. This function will be called exactly once per testcase.playRound
at most 700 times.allValues
. This function will be called exactly once per testcase.playRound
at most 3200 times.playRound
is called. Precisely your score will be:
C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)