This is an interactive problem.
You have purchased a CD set containing $N$ episodes of My Little Pony. Each CD has a label numbered from $1$ to $N$, but the actual episode number stored on each CD does not match its label. It is known that:
- All episodes from $1$ to $N$ are present and unique.
- The mapping between CD label numbers $1$ to $N$ and episode numbers is a permutation.
You need to determine the actual episode number corresponding to each CD label through several rounds of interaction. Each round of interaction proceeds as follows:
- Grouping Phase: Divide the $N$ CDs into $B$ boxes, with each box containing $K$ CDs (it is guaranteed that $N = B \times K$).
- Sending Phase: Send the grouped CDs to your friend, L.
- The order of the boxes will be shuffled.
- The order of the CDs within each box will also be shuffled.
- Receiving Phase: L will:
- Observe the actual episode numbers of the CDs in each box.
- Return the results in an arbitrary order (the original grouping information is not preserved).
You may perform at most $Q$ such interactions. After the interactions are complete, you must determine the episode number corresponding to each CD label.
Implementation Details
You need to implement the following function:
vector<int> solve(int N, int B, int K, int Q, int ST)
Where $ST$ represents the subtask ID.
You must return a vector where the $i$-th element represents the actual episode number of the CD with label $i$.
During the interaction, you may call the following function:
vector<vector<int>> shuffle(vector<vector<int>> boxes)
Parameter description:
boxes: A $B \times K$ 2D array representing the current grouping scheme.- Return value: A $B \times K$ 2D array representing the actual episode numbers of the CDs in each box (in random order).
Notes:
- The number of calls to
shufflecannot exceed $Q$. - Each time
shuffleis called, you must provide a valid grouping scheme ($B$ boxes, each containing $K$ CDs, and including all CD labels from $1$ to $N$).
Examples
Initial conditions:
- $N=6$, $B=3$, $K=2$, $Q=100$
- Actual episode mapping: $[3,1,4,5,2,6]$ (i.e., label 1 → episode 3, label 2 → episode 1, ...)
Interaction process:
- Call
shuffle([[1,2],[3,4],[5,6]])- Might return
[[6,2],[5,4],[3,1]]
- Might return
- Call
shuffle([[2,6],[3,1],[5,4]])- Might return
[[6,1],[2,5],[4,3]]
- Might return
- Call
shuffle([[6,5],[4,2],[3,1]])- Might return
[[5,1],[3,4],[2,6]]
- Might return
Correct output:
- Return
[3,1,4,5,2,6]
Constraints
For all data:
- $B,K\geq 2$
- $N\geq 6$
- $N=B\times K$
Subtasks
| Subtask ID | Special Properties | Score |
|---|---|---|
| $1$ | $N=6$, $B=2$, $K=3$, $Q=100$ | $2$ |
| $2$ | $N=6$, $B=3$, $K=2$, $Q=100$ | $3$ |
| $3$ | $N \leq 1000$, $Q=12$, box order is guaranteed to be preserved when returning results | $15$ |
| $4$ | $N \leq 1000$, $K=2$, $Q=4$ | $20$ |
| $5$ | $N \leq 1000$, $B=2$, $Q=12$ | $20$ |
| $6^{*}$ | $N \leq 1000$, $Q=2000$, $B,K>2$ | $40$ |
$*$ : Subtask $6$ has partial points. Let $q$ be your maximum number of queries:
- $q > 2000$: $0$ points
- $500 < q \leq 2000$: $6$ points
- $50 < q \leq 500$: $15$ points
- $9 < q \leq 50$: $15 + 25 \times (\frac{50-q}{41})^2$ points
- $q \leq 9$: $40$ points