luogu#P16376. [IATI 2026] Triangle

[IATI 2026] Triangle

Problem Description

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\texttt{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:

$$P_A + P_B > P_C,\ P_A + P_C > P_B \quad \text{and} \quad P_B + P_C > P_A.$$

Write a program \textbf{\texttt{triangle}}, containing a function \texttt{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\texttt{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\texttt{query}:

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

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

Input Format

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,\dots,N\}.

Output Format

Output format:

  • line 11: an error message or the average number of queries for the subtests if all permutations are correctly identified.


Hint

Sample Interaction

For this sample interaction N=4N=4, T=2T=2.

Contestant action Jury action
solve(4)
query(0, 0, 0) true
query(0, 1, 2) false
query(0, 1, 3)
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)
return {4, 2, 1, 3};

Constraints

  • N=T=1 000N = T = 1~000

Subtask

Subtask Points Description
11 100100 The subtask consists of 11 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 elements.

The points for a given subtask are obtained only if all the tests for it are successfully passed.

Scoring

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

$$\begin{cases} 0 & \text{if } Q_{contestant} > 2\times 10^6, \\ 100 & \text{if } Q_{contestant} \le Q_{target}, \\ 100 \times \max\left(0.15,\; 1-\sqrt{1-\left(\frac{Q_{target}}{Q_{contestant}}\right)^{0.55}}\right) & \text{if } Q_{contestant} > Q_{target}. \end{cases}$$