시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
2 초 512 MB 1 1 1 100.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.
• The array 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.
• The grader will fill the provided array 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.
• Each subtask specifies a hard limit on the number of times you may call playRound per game. Please note that using fewer calls than this limit may yield a higher scoring solution (see below).

## 점수

• If 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.
• If a function does not correctly determine the required properties of Koala's sequence P for a particular game within a testcase, the entire testcase will be marked as Not Correct, scoring 0.
• Both Subtask 4 and Subtask 5 require you to implement the function 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.
• You may make a maximum of 60 submissions for this task with a minimum interval of 2 minutes between successive submissions.

## 예제

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.

• line 1: two integers F, G;
• line 2 to G + 1: each line contains two integers N, W followed by N integers P0, P1, ..., PN-1 describing a single game.

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.

• If F = 4, the second line contains the contents placed in the array P by your implementation of the function allValues;
• Otherwise, if F = 1, 2 or 3, the second line contains a single integer: the return value of the corresponding function.

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

## 서브태스크 1 (4점)

• In this subtask, the grader will only call the function minValue. This function will be called at most 100 times per testcase.
• N = 100.
• W = 100.
• You may call playRound at most 2 times per game.

## 서브태스크 2 (15점)

• In this subtask, the grader will only call the function maxValue. This function will be called at most 100 times per testcase.
• N = 100.
• W = 100.
• You may call playRound at most 13 times per game.
• The score for a testcase in this subtask depends on the maximum number of times Cmax that playRound is called among all games in that testcase. Precisely your score will be:
• 15 points if Cmax ≤ 4;
• 7 points if 5 ≤ Cmax ≤ 13.

## 서브태스크 3 (18점)

• In this subtask, the grader will only call the function greaterValue. This function will be called at most 1100 times per testcase.
• N = 100.
• W = 100.
• You may call playRound at most 14 times per game.
• The score for a testcase in this subtask depends on the maximum number of times Cmax that playRound is called among all games in that testcase. Precisely your score will be:
• 18 points if Cmax ≤ 3;
• 14 points if Cmax = 4;
• 11 points if Cmax = 5;
• 5 points if 6 ≤ Cmax ≤ 14.

## 서브태스크 4 (10점)

• In this subtask, the grader will only call the function allValues. This function will be called exactly once per testcase.
• N = 100.
• W = 200.
• You may call playRound at most 700 times.

## 서브태스크 5 (53점)

• In this subtask, the grader will only call the function allValues. This function will be called exactly once per testcase.
• N = 100.
• W = 100.
• You may call playRound at most 3200 times.
• The score for a testcase in this subtask depends on the number of times C that playRound is called. Precisely your score will be:
• 53 points if C ≤ 100;
• 53 - 8log2(C/100) points if 101 ≤ C ≤ 3200, where ⌊x⌋ is the greatest integer less than or equal to x. In particular, if C = 3200 your solution will score 13 points.

## 제출할 수 있는 언어

C++17, C++14, C++20, C++14 (Clang), C++17 (Clang), C++20 (Clang)

## 채점 및 기타 정보

• 예제는 채점하지 않는다.