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
Given three pairwise distinct indices
Given two distinct indices
The lower the cost, the more delighted the elephant will be. Help the shark recover the secret permutation.
You should implement the following procedure.
std::vector<int> recoverPermutation(int N)
The above procedure can make calls to the following two procedures to ask questions.
int getMedianValue(int i, int j, int k)
int getLess(int i, int j)
Subtask | Score | Additional Constraints |
---|---|---|
1 | ||
2 | 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
Otherwise, in both subtasks, you can obtain a partial score. Let getMedianValue
and getLess
. In subtask 1, the score is calculated as follows:
Condition | Score |
---|---|
In subtask 2, the score is calculated as follows:
Condition | Score |
---|---|
The plot below shows the number of points as a function of
In particular, to achieve the following scores in subtask 2, your solution must have
Score at Least | Maximum |
---|---|
Note that in some cases, the behaviour of the grader can be adaptive. This means that the value of getMedianValue
and getLess
.
Consider the following call.
recoverPermutation(5)
This means that the
The procedure may call getMedianValue
as follows.
getMedianValue(0, 1, 2)
As the median of
recoverPermutation
may also call getLess
as follows.
getLess(1, 3)
As
The procedure recoverPermutation
then returns
The sample grader is not adaptive. Instead, it receives
Input format:
N P[0] P[1] … P[N-1]
Output format:
Q[0] Q[1] … Q[N-1] C
Here, recoverPermutation
, and
Subtask | Score |
---|---|
1 | 34 |
2 | 66 |
3 | 0 |