#P9529. Dango String Partitioning

    ID: 22676 Type: Default 1000ms 256MiB

Dango String Partitioning

Dango String Partitioning

JOI, a professional dango maker, has prepared a total of (NM) dangos in his shop. There are (N) different colors numbered from (1,2,\dots,N) and for each color he has made exactly (M) dangos. A first‐class dango string is made by skewering exactly (N) dangos, one of each color, onto a bamboo stick. JOI wants to partition the (NM) dangos into (M) groups (each group having exactly (N) dangos and containing all different colors) by making at most (50,000) calls to a detector function. The detector function, when provided a list of dango indices, returns the maximum number of valid first‐class dango strings that can be made by those dangos given a sufficient number of bamboo sticks.

You are required to implement the function [ void; Solve(int; N,; int; M) ] for each test case. Additionally, you are allowed to call the following functions:

• (int; Query(const std::vector&; x)): Takes a list of distinct indices (each between 1 and (NM)) and returns the maximum number of first‐class dango strings that can be assembled from the set. Calling this function more than (50,000) times will result in Wrong Answer.

• (void; Answer(const std::vector&; a)): Reports one valid group (of (N) distinct dango indices forming a valid dango string). This function must be called exactly (M) times, and each dango index (between 1 and (NM)) must appear exactly once in the (M) answers.

In this problem, the underlying dango colors are provided as an array of (NM) integers (each in ({1,2,\dots, N})) in the grader. Although in an interactive setting the colors are hidden and you must use the detector, you are allowed to use your own strategy (possibly involving the detector) to complete the task.

Note: In our sample solution, we assume that the color information is available, and we partition the dangos based on their colors. Each color appears exactly (M) times, so a straightforward strategy is to group the first occurrence of each color together, then the second occurrence of each color, and so on.

inputFormat

The input is given by the grader via an interactive protocol and consists of two parts:

  1. The first line contains two positive integers (N) and (M): the number of different dango colors and the number of first-class dango strings to be formed.

  2. The second line contains (NM) positive integers (C_1,C_2,\dots,C_{NM}) where (C_i) ((1 \le C_i \le N)) represents the color of the (i)-th dango.

outputFormat

Your program must, through (M) calls to the function Answer, report a valid partition of the (NM) dangos into (M) groups. Each group must consist of (N) distinct dango indices and must contain exactly one dango of each color. In the sample solutions provided here, the output is printed as (M) lines, each line containing (N) integers separated by spaces representing a valid group.

sample

3 2
1 2 3 1 2 3
1 2 3

4 5 6

</p>