Ramen

Time limit: 1s Memory limit: 256MB Input: Output:

There are NN friends F0,,FN1F_0, \ldots, F_{N - 1} and NN types of ramen R0,,RN1R_{0}, \ldots, R_{N - 1} at the ramen restaurant. Each friend FiF_i has a certain affinity AijA_{ij} for ramen type jj - the greater the affinity, the more friend FiF_i likes ramen RjR_j. The affinities of each friend are distinct - i.e., AijAijA_{ij} \neq A_{ij'} for jjj \neq j'. Of course, it is possible that Aij<0A_{ij} < 0.

Suppose the friends visit the ramen restaurant multiple times. During each visit, no two friends can eat the same type of ramen (the supply would be insufficient). Suppose that the friends take their ramen in order Fπ0,,FπN1F_{\pi_0}, \ldots, F_{\pi_{N - 1}}, for some permutation π0,,πN1\pi_0, \ldots, \pi_{N - 1} of 0,,N10, \ldots, N - 1. Then, friend Fπ0F_{\pi_0} will take their favorite ramen (i.e., the one for which they have the highest affinity), friend Fπ1F_{\pi_1} will take their favorite ramen except the one taken by Fπ0F_{\pi_0}, and so on. In other words, FπiF_{\pi_i} will take their favourite ramen among those not taken by Fπ0,,Fπi1F_{\pi_0}, \ldots, F_{\pi_{i - 1}}.

The goodness of a certain permutation π\pi is the sum of the affinities of the friends for the types of ramen they take. In other words, if friend ii takes ramen of type σi\sigma_i, then the goodness of π\pi is given by i=0N1Ai,σ(i)\sum_{i = 0}^{N - 1} A_{i, \sigma(i)}.

Your goal is to find a permutation π\pi with maximum goodness. You can do this by experimenting with different orders in which the friends take their ramen (i.e., different visits to the restaurant). The goal is to find an optimal permutation without needing too many visits to the restaurant.

Interaction protocol

You have to implement the following function:

std::vector<int> find_order(int N);

Here, NN is the number of friends. The function should return a permutation π\pi of 0,,N10, \ldots, N - 1 with maximum goodness. To implement it, you may repeatedly call the following function at most 750750 times:

std::vector<std::pair<int, int>> query(const std::vector<int>& order);

The function takes as input a permutation π\pi of 0,,N10, \ldots, N - 1 (denoted by the parameter order) and returns a list of pairs (σ(i),Ai,σ(i))(\sigma(i), A_{i, \sigma(i)}), where σ(i)\sigma(i) is the type of ramen that friend ii takes if the friends take their ramen in the order given by π\pi.

Constraints

  • 1N751 \leq N \leq 75
  • Aij2 000 000| A_{ij} |\leq 2 \ 000 \ 000
  • The model solution of the scientific committee requires at most cNkcN^k queries for some constants c,k1c, k \geq 1. To not overburden the testing infrastructure, you may call query at most 750750 times, which generously reflects the practical performance of the model solution.

Example

Competitor behaviour Committee behaviour
Calls find_order(2).
query({0, 1}) {{0, 9}, {1, 0}}
query({1, 0}) {{1, 5}, {0, 5}}
find_order(2) returns {1, 0}

Explanation

In this example, there are N=2N = 2 friends, with the following affinities Ai,jA_{i, j} for the N=2N = 2 types of ramen:

(9550)\begin{pmatrix} 9 & 5 \\ 5 & 0 \end{pmatrix}

The interaction begins with the committee calling your function: find_order(2). Your function then queries the two possible permutations: {0,1}\{0, 1\} and {1,0}\{1, 0\}. The former achieves a goodness of 0+9=90 + 9 = 9, while the latter achieves a goodness of 5+5=105 + 5 = 10. The function then returns the better of the two, which is {1,0}\{1, 0\}. The returned permutation has the maximum possible goodness, as required.

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