enwisen

Description

Long ago, at the dawn of civilization, there lived an elephant. It was bipedal, with a cactus-like body and feet clad in technologically advanced footwear. This elephant was renowned for its wisdom. One day, an extravagant creature came to visit: a shark that had evolved four limbs, each equipped with similarly advanced footgear.

"O elephant," the shark beseeched, "make me wise!"

"Before I enwisen thee," the elephant replied, "thou must first complete my challenge."

The elephant has a secret permutation P of {0,1,,N1}. The elephant challenges the shark to recover this permutation by asking questions of two types, each with an associated cost:

  1. Given three pairwise distinct indices i, j, and k, what is the median of P[i], P[j], and P[k]? (Here, the median is the element which is neither the minimum nor the maximum). The cost of asking this question is 1.

  2. Given two distinct indices i and j, which one of P[i] and P[j] is smaller? The cost of asking this question is N.

The lower the cost, the more delighted the elephant will be. Help the shark recover the secret permutation.

Implementation Details

You should implement the following procedure.

std::vector<int> recoverPermutation(int N)
  • N: the length of the permutation.
  • This procedure should return an array Q of length N, representing the elephant's secret permutation.
  • This procedure is called exactly once for each test case.

The above procedure can make calls to the following two procedures to ask questions.

int getMedianValue(int i, int j, int k)
  • i, j, k: the indices to ask. It must be satisfied that 0i,j,kN1 and that i, j, and k are pairwise distinct.
  • This procedure returns the median of P[i], P[j], and P[k].
int getLess(int i, int j)
  • i, j: the distinct indices to ask. It must be satisfied that 0i,jN1 and ij.
  • This procedure returns i if P[i]<P[j], and j otherwise.

Constraints

  • 4N60000
  • The secret permutation P is valid. Formally, 0P[i]N1 for 0iN1, and P[i]P[j] for 0i<jN1.

Subtasks and Scoring

Subtask Score Additional Constraints
1 34 N1000
2 66 No additional constraints.

If in any of the test cases, the calls to the procedures do not conform to the rules above, or the return value of the procedure recoverPermutation is incorrect, the score of your solution for that test case will be 0.

Otherwise, in both subtasks, you can obtain a partial score. Let C be the total cost across all calls of getMedianValue and getLess. In subtask 1, the score is calculated as follows:

Condition Score
5×108<C 0
107<C5×108 4
2000000<C107 9
1100000<C2000000 21
C1100000 34

In subtask 2, the score is calculated as follows:

Condition Score
106<C 0
239996C106 20+100×1.00000560000C
C239995 66

The plot below shows the number of points as a function of C your solution will get in subtask 2.

In particular, to achieve the following scores in subtask 2, your solution must have C be at most the following values.

Score at Least Maximum C
20 1000000
30 520518
40 381888
50 300759
60 243258
66 239995

Note that in some cases, the behaviour of the grader can be adaptive. This means that the value of P is not fixed in advance. Instead, the grader may freely change the value of P during execution, as long as there is at least one value of P consistent with all previous return values of getMedianValue and getLess.

Example

Consider the following call.

recoverPermutation(5)

This means that the P is a permutation of {0,1,2,3,4}. Suppose that for this example, P=[2,4,3,0,1].

The procedure may call getMedianValue as follows.

getMedianValue(0, 1, 2)

As the median of 2, 4, and 3 is 3, this procedure will return 3. The cost of this question is 1.

recoverPermutation may also call getLess as follows.

getLess(1, 3)

As P[1]>P[3], this procedure will return 3. The cost of this question is N=5.

The procedure recoverPermutation then returns [2,4,3,0,1]. The total score used across all questions is 1+5=6. Based on the scoring formulas mentioned above, full score is given.

Sample Grader

The sample grader is not adaptive. Instead, it receives P as its input.

Input format:

N
P[0] P[1] … P[N-1]

Output format:

Q[0] Q[1] … Q[N-1]
C

Here, Q is the permutation returned by recoverPermutation, and C is the total cost used by your solution across all questions.



Submitting .cpp to 'enwisen'


You're not logged in! Click here to login

Time Limit: 2.5 Seconds
Memory Limit: 1024MB
Your best score: 0
Source: SEATST 2025 (Day 1)

Subtask Score
1 34
2 66
3 0