Jiajia and Dongdong participated in the National Olympiad in Informatics in Provinces (NOIP) winter camp held in Mianyang, Sichuan. Today is a rest day, and being bored, they decided to play the classic number guessing game.
The rules of the game are as follows: Jiajia thinks of a decimal four-digit number $a_1a_2a_3a_4$ in her mind, with the constraint $a_1 \neq a_2 \neq a_3 \neq a_4$, where $a_1$ can be $0$. Dongdong first guesses a decimal four-digit number $b_1b_2b_3b_4$, where $b_1 \neq b_2 \neq b_3 \neq b_4$, and $b_1$ can be $0$. After the guess, Jiajia immediately compares $b_1b_2b_3b_4$ with $a_1a_2a_3a_4$ and replies with two integers $P$ and $Q$. $P$ represents the number of digits that are correct in both value and position, while $Q$ represents the number of digits that are correct in value regardless of their position. If Dongdong does not guess correctly, he can continue to guess until he gets it right. Dongdong's goal is to minimize the number of guesses.
For example, if the number Jiajia is thinking of is $6703$: First guess, Dongdong guesses $1980$, Jiajia replies $P=0, Q=1$. Second guess, Dongdong guesses $0731$, Jiajia replies $P=1, Q=3$. Third guess, Dongdong guesses $6703$, Jiajia replies $P=4, Q=4$. Thus, the game ends, and Dongdong guessed the number in only three attempts.
Dongdong felt great about his initial success, but later found it difficult to guess the numbers Jiajia was thinking of. He wondered if he could use a computer to help him guess the number in as few attempts as possible. After several hours of intense searching online, Dongdong finally found the number-guessing program Jiajia had written $y$ years ago. Just as Dongdong was happily preparing to play the game with Jiajia again using the program, Jiajia cheekily told him she was changing the rules to increase the difficulty. The rules were changed to guessing a number of length $L$ ($2 \le L \le 9$). This time, Jiajia's program was of no use; Dongdong spent ten attempts to guess a number of length $L=1$, and failed to guess any others.
Dongdong felt frustrated and hoped to find a new program, pinning all his hopes on you.
Dongdong has already hired an expert to write a "shell." Your task is to write the guessing process. To be compatible with the "shell," you need to call library functions to interact with the user. You do not need to worry about how the "shell" works.
This is an interactive problem. Your program cannot directly perform file operations but must call library functions to complete the corresponding tasks. The system provides a data type TNumber and three library functions: Len, tryNumber, and Next. Their descriptions and usage methods are as follows:
TNumber: An array type containing at most 10 bytes, used for passing parameters to thetryNumberfunction.Len: A function to get the length $L$ of the number to be guessed; it can be called any number of times.tryNumber(N, P, Q): Where $N$ is of typeTNumber, representing the guessed number, and $P, Q$ are two integers. After calling this function, the library will return the values of $P$ and $Q$ based on the difference between $N$ and the target number.Next: To evaluate your program, it may be required to guess multiple numbers in succession. After guessing one number (a number is considered guessed only when the $P$ and $Q$ values returned bytryNumberare both equal to $L$), you need to callNextto proceed to the next number. If all numbers have been guessed, the library will automatically exit whenNextis called.
The definitions of the above data types and functions in Pascal and C++ are as follows:
| Type/Function | Pascal | C++ |
|---|---|---|
TNumber |
type TNumber = array[0..9] of byte; |
typedef char TNumber[10]; |
Len |
function Len: integer; |
int Len(); |
tryNumber |
procedure tryNumber(const N: TNumber; var P, Q: integer); |
void tryNumber(const TNumber N, int &P, int &Q); |
Next |
procedure Next; |
void Next(); |
If you are using the Pascal language, use the statement Uses GuessLib_p; to reference the provided unit.
If you are using the C++ language, include the file GuessLib_c.o in your project and add the line #include "GuessLib_c" at the beginning of your program.
Implementation Details
You can create a file named guess.in in your directory. The first line of the file contains two integers $n$ and $L$, representing the number of integers to guess and the length of the numbers, respectively. The next $n$ lines each contain $L$ distinct integers from $0$ to $9$, separated by spaces. The $(i+1)$-th line represents each digit of the $i$-th number to be guessed.
For your convenience in debugging, we have included a process in the library to randomly generate the numbers to be guessed. If the length $L$ is negative, the library will randomly generate $n$ numbers of length $-L$, without needing to put these numbers into guess.in. Therefore, the input file can contain only two integers $n$ and $L'$, representing the number of target numbers and the negative of their length.
Once the input file is created, you can run the program you have written. All intermediate results will be placed in guess.log. It generally contains the following information:
Game started.: The game has started.The number is [<Number>]: The current number to be guessed is<Number>.<ID> Guess [<Number>] P=<P> Q=<Q>: ThetryNumberfunction was called once with the parameter<Number>, returning $P$ as<P>and $Q$ as<Q>, where<ID>is the call sequence number.<T> Times.:Nextwas called, and a total of<T>calls totryNumberwere made to guess the previous number.Finished. Average query: <Ave>: All numbers have been guessed, with an average ofAvequeries used.Error: Number is invalid.: The parameters fortryNumberare invalid.Error: Invalid call of Next.: TheNextfunction was called before the current number was guessed.Error: Too many numbers.: There are too many numbers to guess in the input file.Error: Input file error.: The input file format is incorrect.
Examples
Input 1
1 4 6 7 0 3
Output 1
(See guess.log for execution details)
Note
The guess.log file for the above example would contain:
Game started. The number is [6703] 1 Guess [1980] P=0 Q=1 2 Guess [0731] P=1 Q=3 3 Guess [6703] P=4 Q=4 3 Times. Finished. Average query: 3.00
Subtasks
For each test case, there will be many numbers for your program to guess, and you must guess all of them within the specified time. Finally, your score is calculated based on the average number of attempts Ave used for each number and the two reference values Good and Bad ($Good < Bad$) provided before the test, using the following formula:
$$ Score = \begin{cases} 10 & (Ave \le Good) \\ 2 + 8 \times \left( \frac{Bad - Ave}{Bad - Good} \right)^2 & (Good < Ave < Bad) \\ 2 & (Ave \ge Bad) \end{cases} $$
Where $\lfloor a \rfloor$ denotes the integer part of $a$.
Additionally, if your program exhibits any of the following, the corresponding test case will receive $0$ points: No source code or the source code fails to compile. Reading or writing any files. Reading or writing the memory of library functions or library variables. Illegal function calls. Causing the library to exit abnormally. Terminating execution on its own. Exceeding space or time limits. Other situations where the library fails to generate the average number of attempts and exit normally.
Test Case Information
| Test Case ID | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|
| Len | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 10 |
| Count | 100 | 100 | 100 | 100 | 100 | 20 | 20 | 20 | 1 | 20 |
Note
- All numbers in the same dataset have the same length, and all numbers to be guessed are given randomly.
- The
BadandGoodvalues for the 9th test case will be relatively large.