#P3777. Koala's Game: Determining Hidden Permutations

    ID: 17027 Type: Default 1000ms 256MiB

Koala's Game: Determining Hidden Permutations

Koala's Game: Determining Hidden Permutations

Koala has invented a new game and invites you to play! The game begins with Koala placing N items labeled from 0 to N-1 on the table. She secretly assigns a unique integer weight to each item, where the weights form a permutation of the numbers 1 through N. In other words, for each item i, its weight is Pi and every weight from 1 to N is used exactly once.

You are allowed to play several rounds with Koala in order to learn some features of the hidden permutation P = P0, P1, ..., PN-1. In each round, you get W blue stones and Koala gets W red stones. The round proceeds as follows:

  • You select some items and place some (or all) of your blue stones beside these items.
  • After observing your placement, Koala places some (or all) of her red stones beside some items.

An item is acquired by Koala if the number of red stones placed on it is strictly greater than the number of blue stones placed on that item. Koala always chooses her placement strategy to maximize the sum of weights of the items she acquires. If there are multiple ways to achieve the maximum weight sum, she then chooses the strategy that gains the maximum number of items; if still tied, any strategy is used.

Your objective is to implement four functions that determine different characteristics of the hidden permutation. Note: In your submissions you are not allowed to perform any input/output operations (i.e. no standard input reading or standard output writing) or file interactions. Instead, you can use the provided function playRound to interact with Koala.

The functions you need to implement are as follows:

  1. minValue(N, W): Return the index i of the item with the minimum weight, i.e. where Pi = 1.
  2. maxValue(N, W): Return the index i of the item with the maximum weight, i.e. where Pi = N.
  3. greaterValue(N, W): Compare the weights of item 0 and item 1, and return the index of the heavier one. In other words, if P0 > P1 return 0; otherwise, return 1.
  4. allValues(N, W, P): Determine the entire permutation and store it in the provided array P such that P[i] is the weight of item i (for 0 ≤ i < N).

Note: Each function call represents an independent task. Koala chooses her hidden permutation before the call and may change it between calls. You are allowed to call playRound to gather information, but the number of calls is limited.

For the purpose of this sample solution, we provide a trivial implementation that always assumes the hidden permutation is the identity permutation (i.e. P[i] = i+1). This solution is intended to pass the sample test cases but may not work for all possible instances of the game.

inputFormat

This problem does not take any standard input. Instead, your solution must implement the following four functions:

  • minValue(N, W)
  • maxValue(N, W)
  • greaterValue(N, W)
  • allValues(N, W, P)

Each function receives two integers, N (the number of items) and W (the number of stones available in each round). For allValues a third parameter, an array P, is provided where you should store the permutation.

outputFormat

Your functions should return the correct index or, in the case of allValues, fill the array P with the hidden permutation. There is no output to standard output.

sample

Call: minValue(5, 10)
0