triangle

Time limit: 5s Memory limit: 1024MB Input: Output:

The new leadership of the national committee, represented by the coordinators of groups A and B, wishes to maintain a strict syllabus of the given problems for selecting the national team. For this purpose, they will need to give a geometry problem. Moreover – the number of interactive problems given so far are below standard. To fix the crisis in the selection for IOI, Sashka decided to give a problem that is both interactive and geometric. It has the following statement:

The jury has hidden a permutation P0,P1,...,PN1P_0, P_1, ..., P_{N-1} of {1,2,3,...,N}\{1, 2, 3, ..., N\}. You must find the permutation. For this purpose, you may ask the jury the following question: “Is it possible to form a triangle with positive area with sides PA,PB,PCP_A, P_B, P_C?”

Note that it is known (by the triangle inequality) this is possible if and only if: PA+PB>PC,PA+PC>PBP_A+P_B>P_C,P_A+P_C>P_B and PB+PC>PAP_B+P_C>P_A

Write a program triangle, containing a function solve, which will be compiled together with the jury program and will communicate with it by asking questions of the type described above. At the end of its execution, it must determine the permutation.

Implementation details

You should implement the solve function:

std::vector<int> solve(int N)
  • NN: length of the permutation.

This function will be called TT times per test – once per subtest, each with equal NN and it should return the hidden permutation for the subtest. In order to do this, your program can call the jury function query:

bool query(int A, int B, int C)
  • A,B,CA,B,C: indices of the sides PA,PB,PCP_A, P_B, P_C.

The function returns true, if a triangle with positive area with sides PA,PB,PCP_A,P_B,P_C exists and false, otherwise.

Constraints and clarifications

  • N=T=1 000N = T = 1 \ 000
Subtask Points Description
1 100 The subtask consists of 1 test with T=1 000T = 1 \ 000 randomly and uniformly sampled from the set of all possible permutations, each of N=1 000N = 1 \ 000

Scoring

Let QcontestantQ_{contestant} be the average number of queries that your program for one call of solve on the single test, and let Qtarget=8 770Q_{target} = 8 \ 770. Then your score for the problem will be:

{0if Qcontestant>2106100if QcontestantQtarget100max(0.15,11(QtargetQcontestant)0.55)if Qcontestant>Qtarget\left\{ \begin{aligned} 0 &\quad \text{if } Q_{contestant} > 2 \cdot 10^6 \\ 100 &\quad \text{if } Q_{contestant} \leq Q_{target} \\ 100 \cdot \max \left(0.15, 1 - \sqrt{\smash[b]{1 - \left( \frac{Q_{target}}{Q_{contestant}} \right)^{0.55}}} \right) &\quad \text{if } Q_{contestant} > Q_{target} \end{aligned} \right.

Sample interaction

Contestant action Jury action
solve(4)
query(0, 0, 0) true
query(0, 1, 2) false
query(0, 1, 3) false
query(0, 2, 3) true
query(1, 2, 3) false
return {3, 1, 2, 4};
solve(4)
query(0, 1, 2) false
query(0, 1, 3) true
query(0, 2, 3) false
query(1, 2, 3) false
return {4, 2, 1, 3};

Local testing

Input format:

  • line 11: three integers TT, NN, and RR – the number of subtests, the size of the permutations, and the execution mode. If R=1R=1, the local grader will generate uniformly random permutations and will expect a number on the second line – SS, which will be the seed for its random generator. If R=2R=2, the input continues as follows:
  • lines 22 to (1+T)(1 + T): permutations of {1,2,...,N}\{1, 2, ..., N\}.

Output format:

  • line 11: an error message or the average

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