Secret Permutation

Time limit: 2s Memory limit: 64MB Input: secret-permutation.in Output: secret-permutation.out

Task

The Scientific Committee has hidden from you a permutation PP of all the integers from 11 to NN. You need to find it. Permutation PP is fixed (the grader is not adaptive).

Interaction protocol

Your solution to this problem must be written inside this function:

void solve(int N);

You are free to write and call additional functions but you're not allowed to write a main() function.

In your endeavor, you are allowed to ask queries that take as parameter another permutation VV of all the integers from 11 to NN:

int query(std::vector<int> V);

This function will return i=1N1abs(P[V[i]]P[V[i+1]])\sum_{i = 1}^{N-1} abs(P[V[i]] - P[V[i + 1]]). Whenever you want to perform a query, call this function with a permutation VV of all the integers from 11 to NN as parameter. You will be graded based on the number of times you call this function. Performing a number of queries, you are to discover permutation PP, or any other permutation PP' that is indistinguishable from PP.

When you're confident you've discovered permutation PP, call this function with PP as a parameter.

void answer(std::vector<int> P);

Calling this function will terminate the program.

Note that both permutations PP and VV are represented as a 00-indexed std::vector<int> when supplied as parameters.

Sample implementation

Sample code to illustrate the Interaction section:

#include "permutation.h"

void solve(int N) {
  if (N == 2) {
    std::vector<int> V = {1, 2};
    int qAns = query(V);
    if (qAns == 1) {
      std::vector<int> P = {1, 2};
      answer(P);
    }
  }
}

Sample grader

For local testing you can download two files from "Attachments": grader.cpp and permutation.h.

The Grader reads from Standard Input an integer NN - the size of the hidden permutation and NN distinct integers - the hidden permutation. Then, the Grader calls the solve() function you must implement.

At Standard Output the Grader will output:

  • for every query() call: the queried permutation and the answer to the query;
  • for the answer() call: the verdict (Correct or Wrong Answer), NN and QQ - the size of the permutation and the number of queries you used.

Constraints and clarifications

  • 3N2563 \leq N \leq 256
  • Two permutations are indistinguishable if queried in all possible ways they both yield the same answers.
# Points Restrictions
1 15 3N73 \leq N \leq 7
2 35 3N503 \leq N \leq 50
3 50 3N2563 \leq N \leq 256

Scoring

Each of the test cases is scored as follows:

If you fail to discover one of the correct permutations, then 0%0\% of the score is awarded.

Otherwise, let QQ be the number of queries you needed to solve the test case.

  • If QNQ ≤ N then 100%100\% of the score is awarded.
  • If NQ2NN ≤ Q ≤ 2 \cdot N queries then (10040(QN)N)%\displaystyle \left(100 - \frac{40 \cdot (Q - N)}{N} \right)\% (between 60%60\% and 100%100\% , increasing as QQ decreases) of the score is awarded.
  • If 2NQN22 \cdot N ≤ Q ≤ N^2 queries then (6040(Q2N)N22N)%\displaystyle \left(60- \frac{40 \cdot (Q - 2 \cdot N)}{N^2 - 2 \cdot N}\right)\% (between 20%20\% and 60%60\% , increasing as QQ decreases) of the score is awarded.
  • If N2QN^2 ≤ Q then 20%20\% of the score is awarded.

The total score of this task will be rounded to 22 decimal places.

Log in or sign up to be able to send submissions!