#P9529. [JOIST 2022] 一流团子师傅 / Super Dango Maker

    ID: 10803 远端评测题 10000ms 1024MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2022交互题Special JudgeO2优化JOI(日本)

[JOIST 2022] 一流团子师傅 / Super Dango Maker

Background

JOISC2022 D4T1.

Special reminder: due to the special nature of Luogu’s interactive mechanism, you cannot include dango3.h in your program. Instead, you need to paste the content of dango3.h at the beginning of your file. That is, add the following lines before void Solve(int N, int M) in your program:

#include <vector>

void Solve(int N, int M);

int Query(const std::vector<int> &x);
void Answer(const std::vector<int> &a);

Problem Description

JOI is a professional dango maker. In JOI’s shop, the colors of dango are handled very carefully. There are a total of NN colors, numbered 1,2,,N1,2,\dots,N.

A first-class dango skewer is the signature product of JOI’s shop. To make one first-class dango skewer, you need to put NN dango of different colors onto one bamboo stick.

For each color, JOI has made MM dango of that color. Therefore, JOI has a total of NMNM dango. These dango are numbered 1,2,,NM1,2,\dots,NM. Using these dango and MM bamboo sticks, JOI wants to make MM first-class dango skewers.

To avoid making mistakes about colors, JOI will use his dango detector. If JOI inputs the indices of some dango, the detector will return the maximum possible number of first-class dango skewers that can be made using those dango. Of course, this is under the condition that the bamboo sticks are fully used.

JOI wants to use the dango detector several times to divide the NMNM dango into MM groups, where each group contains NN dango and contains exactly one dango of each color.

JOI wants to finish this task using the dango detector no more than 5000050\,000 times.

Please write a program that, given the information about the dango, implements a strategy for JOI to complete the task using the dango detector no more than 5000050\,000 times.


Implementation Details

Your program must implement the following function.

  • void Solve(int N, int M).
    For each test case, this function is called exactly once.
    • Parameter N is the number of dango colors NN.
    • Parameter M is the number of first-class dango skewers JOI wants to make, MM.

Your program may call the following functions.

  • int Query(const std::vector<int> &x).
    Your program can call this function to use the dango detector.

    • Parameter x is the list of indices of dango given to the detector.
    • The function returns the maximum number of first-class dango skewers that can be made using the dango in x.
    • Each element of x must be an integer in [1,NM][1,NM]. Otherwise, your program will be judged Wrong Answer [1].
    • The elements of x must be pairwise distinct. Otherwise, your program will be judged Wrong Answer [2].
    • Your program must not call this function more than 5000050\,000 times. Otherwise, your program will be judged Wrong Answer [3].
  • void Answer(const std::vector<int> &a).
    Your program can call this function to report a grouping scheme.

    • Parameter a is the list of indices of one group of dango you formed.
    • The length of a must be NN. Otherwise, your program will be judged Wrong Answer [4].
    • Each element of a must be an integer in [1,NM][1,NM]. Otherwise, your program will be judged Wrong Answer [5].
    • Throughout the whole process, the same dango must not appear in the parameter more than once. Otherwise, your program will be judged Wrong Answer [6].
    • If the dango in a cannot form a first-class dango skewer, your program will be judged Wrong Answer [7].
    • This function must be called exactly MM times. Otherwise, your program will be judged Wrong Answer [8].

Hints

  • Your program may implement other functions for internal use, or use global variables.
  • Your program must not use standard input/output streams, and must not access any files in any way. However, you may print debug information to the standard error stream.

Compilation and Test Run

You can download the sample grader from “Additional Files” to test your program. “Additional Files” also provides a sample of the program you should submit.

The sample grader is grader.cpp. To test your program, put grader.cpp,dango3.cpp in the same directory, and compile your program using the following command.

g++ -std=gnu++17 -O2 -o grader grader.cpp dango3.cpp

If compilation succeeds, an executable file grader will be generated.

Note that the actual grader used is different from the provided sample grader. The sample grader only has a single process: it reads input from standard input and outputs the result to standard output.

Sample Grader Input Format

The first line contains two positive integers N,MN,M, which represent the number of colors and the number of first-class dango skewers JOI wants to make.

The second line contains N×MN\times M positive integers C1,C2,,CNMC_1,C_2,\dots,C_{NM}. Here, CiC_i is a positive integer in [1,N][1,N], representing the color of the ii-th dango.

Sample Grader Output Format

  • If your program is judged correct, the sample grader outputs the number of calls to Query, such as “Accepted: 2022\texttt{Accepted: 2022}”.
  • If your program is judged as any kind of Wrong Answer, the sample grader outputs its type, such as “Wrong Answer [4]\texttt{Wrong Answer [4]}”.

If your program falls into multiple Wrong Answer types, the sample grader will output only one of them.

Hint

Sample Interaction

Here is a sample input for the sample grader and the corresponding interaction process.

3 2
3 3 1 2 1 2
Call Return value
Solve(3, 2)\texttt{Solve(3, 2)}
Query([])\texttt{Query([])} 0\texttt 0
Query([4, 2, 1, 3])\texttt{Query([4, 2, 1, 3])} 1\texttt 1
Query([3, 4, 5])\texttt{Query([3, 4, 5])} 0\texttt 0
Query([2, 6, 5])\texttt{Query([2, 6, 5])} 1\texttt 1
Query([6, 5, 4, 3, 2, 1])\texttt{Query([6, 5, 4, 3, 2, 1])} 2\texttt 2
Answer([1, 6, 5])\texttt{Answer([1, 6, 5])}
Answer([2, 3, 4])\texttt{Answer([2, 3, 4])}

Note that this sample does not satisfy the limits of any subtask.

You can download sample-02.txt\texttt{sample-02.txt} from “Additional Files”. It satisfies the limits of Subtask 11.

Constraints

For all testdata, the following hold:

  • 1CiN1 \le C_i \le N (1iNM)(1 \le i \le NM).
  • For each jj (1jN)(1 \le j \le N), there are exactly MM indices ii (1iNM)(1 \le i \le NM) such that Ci=jC_i = j.
  • N,MN,M are positive integers.
  • CiC_i (1iNM)(1 \le i \le NM) is an integer in [1,N][1,N].

The additional constraints and scores of the subtasks are given in the table below:

Subtask ID Additional constraints Score
11 N=M=4N=M=4 22
22 N=100N=100, M=10M=10 55
33 N=200N=200, M=25M=25 1515
44 N=400N=400, M=25M=25 7878

Translated by ChatGPT 5