#P9512. [JOI Open 2023] 古代机器 2 / Ancient Machine 2
[JOI Open 2023] 古代机器 2 / Ancient Machine 2
Background
Translated from JOI Open 2023 T1 「古代の機械 2 / Ancient Machine 2」.
This is an interactive problem.
Before submitting this problem, be sure to carefully read the following content.
This problem only supports C++ submissions (C++14 is recommended; please do not use C++14 (GCC9)).
Due to Luogu’s special interactive mechanism, when submitting this problem, please remove the line #include "ancient2.h" from your code, and paste the following line at the very beginning of your code:
int Query(int m, std::vector<int> a, std::vector<int> b);
Problem Description
Bitaro and Bibako are archaeologists who excavate and investigate the ruins of the JOI Kingdom. In the ruins, Bitaro found an ancient stone tablet, and Bibako found an ancient machine.
From the research results, Bitaro found that a string of length is written on the tablet. Each character of the string is either 0 or 1. However, he still does not know what each character in is.
On the other hand, from the research results, Bibako figured out how to use the machine. To use it, we need to place the tablet on the machine, input an integer and two integer sequences , and then make one query. Here, the integer and the sequences must satisfy the following conditions:
- The integer is between and (inclusive).
- The lengths of the sequences and are both .
- Each element of the sequences is an integer between and (inclusive).
If we place the tablet on the machine, input an integer and two integer sequences , and then make one query, the machine will operate as follows and display an integer.
-
The machine sets its memory area to .
-
The machine performs the following operation times. The -th operation () is performed as follows.
Let be the current integer in the machine’s memory area. The machine reads the character , where is the -th character of the string (0-indexed).
- If is
0, the machine sets the memory area to , where is the -th element of sequence (0-indexed). - If is
1, the machine sets the memory area to , where is the -th element of sequence (0-indexed).
- If is
-
The machine displays the integer finally stored in the memory area.
Using this machine, Bitaro wants to determine the string written on the tablet. However, because the machine is very fragile, the number of queries must not exceed . Also, the maximum value of the integer input to the machine should be as small as possible.
Using this machine, write a program to determine the string written on the tablet.
Implementation Details
At the beginning of your program, you need to include the library ancient2.h using the preprocessing directive #include. It should implement the following function.
-
std::string Solve(int N)This function is called exactly once for each testdata. This function must return the same string as the string written on the tablet.
- The parameter
Nrepresents the length of the string written on the tablet. - This function must return a string of length . If the returned string does not have length , your program will be judged Wrong Answer [1].
- Each character of the returned string must be either
0or1. If this condition is not satisfied, your program will be judged Wrong Answer [2]. - The returned string must be identical to the string written on the tablet. If this condition is not satisfied, your program will be judged Wrong Answer [3].
Your program may call the following function.
-
int Query(int m, std::vector<int> a, std::vector<int> b)By using this function, your program can make one query.
- The parameter
mis the integer input to the machine. - The parameters
aandbare the two integer sequences input to the machine. - The return value is the integer displayed by the machine at the end when we place the tablet on the machine, input the above integer and sequences, and make one query.
- The parameter
mmust be between and (inclusive). If this condition is not satisfied, your program will be judged Wrong Answer [4]. - The lengths of sequences
aandbmust both be equal to . If this condition is not satisfied, your program will be judged Wrong Answer [5]. - Each element of sequences
aandbmust be between and (inclusive). If this condition is not satisfied, your program will be judged Wrong Answer [6]. - The number of calls to the function
Querymust not exceed . If it exceeds , your program will be judged Wrong Answer [7].
- The parameter
- The parameter
Notes
- Your program may implement other functions for internal use, or use global variables.
- Your program is not allowed to use standard input/output. Your program is not allowed to communicate with other files in any way. However, your program may output debug information to standard error output.
Compilation and Test Run
You can download the sample grader from “Files” → “Additional Files” to test your program. The “Additional Files” also include a sample source file of your program.
The sample interactor is the file grader.cpp. To test your program, you need to put the three files grader.cpp, ancient2.cpp, and ancient2.h in the same folder, and compile your program using the following command. You can also run compile.sh to compile your program.
g++ -std=gnu++17 -O2 -o grader grader.cpp ancient2.cpp
When compilation succeeds, an executable file grader will be generated.
Note that the actual interactor is different from the sample one. The sample interactor runs as a single process, meaning it reads input data from standard input and outputs results to standard output.
Input Format
The first line contains an integer .
The second line contains a string of length .
Output Format
The sample interactor outputs the following content to standard output.
- If your program is judged correct, it outputs the maximum value of the parameter
mamong all calls toQuery, for example,Accepted: 22. However, if your program is judged correct without callingQuery, it outputsAccepted: 0. - If your program is judged with any type of wrong answer, the sample interactor outputs its category, for example,
Wrong Answer [4].
If the program satisfies multiple wrong answer categories, the sample interactor will output only one of them.
3
110
Accepted: 4
Hint
Sample Explanation
The sample function calls are as follows.
Call to Solve |
Return value | Call to Query |
Return value |
|---|---|---|---|
Solve(3) |
|||
Query(4, [3, 3, 2, 2], [2, 2, 1, 0]) |
3 |
||
Query(2, [0, 1], [1, 0]) |
0 |
||
Query(1, [0], [0]) |
|||
Query(3, [1, 1, 1], [1, 1, 1]) |
1 |
||
"110" |
|||
Suppose the string written on the tablet is 110. If we place the tablet on the machine, input , and make one query, the machine will operate as follows.
- The machine sets the memory area to .
- In the first operation, since is
1, the machine sets the memory area to , i.e. . - In the second operation, since is
1, the machine sets the memory area to , i.e. . - In the third operation, since is
0, the machine sets the memory area to , i.e. . - Since the integer finally stored in the memory area is , the machine displays .
Note that this sample input does not satisfy the constraint . In the files, sample-02.txt satisfies this constraint.
Constraints
For all testdata, the following hold:
- is a string of length
- Each character of is either
0or1
For each testdata, the actual interactor is not adaptive. This means the answer is already fixed when the interactor starts.
If your program is judged with any type of wrong answer on any testdata, you will receive points for this problem.
If your program is judged correct on all testdata, your score is determined by , where is the maximum value of the parameter m among all calls to Query. However, if your program is judged correct without calling Query, your score is determined with .
- If , your score is .
- If , you will receive points.
Here, denotes the greatest integer not exceeding .
Translated by ChatGPT 5