No.3501 Digit Products 2
タグ : / 解いたユーザー数 97
作問者 :
2251799813685248
/ テスター :
Solalyth
Problem Statement
This is an interactive problem (a problem in which your program and the judge system communicate through input and output).
The judge holds a hidden positive integer $X$ that has $N$ digits in base $10$.
Find $X$ by asking the following question at most $N$ times.
However, if, after asking at most $N$ questions, you find that $X$ cannot be determined as exactly $1$ possibility no matter how at most $N$ questions are asked, report that instead.
- Specify $2$ different digits in the base-$10$ representation of $X$ and ask for their product.
Constraints
- $2 \leq N \leq 51$
- $X$ is a positive integer that has $N$ digits in base $10$, without leading zeros
Input and Output
First, receive $N$ from standard input in the following format.$N$
Next, ask at least $0$ and at most $N$ questions in the following format.
- When asking the judge a question
To ask for the product of the $10^a$'s digit and the $10^b$'s digit, print to standard output in the following format. Here, $a,b$ must have no leading zeros and must satisfy $0 \leq a < b \leq N-1$.
$?\ a\ b$
The judge's response is given from standard input in the following format.
$p$
Here, $p$ is the product of the $10^a$'s digit and the $10^b$'s digit of $X$.
However, if you print output in an invalid format during the interaction, or if the number of questions exceeds $N$, then $p = -1$.
In this case, the judge program has already terminated and your submission has been judged as incorrect, so stop your program immediately. Otherwise, the judge result is undefined.
- When answering the problem
When you have finished asking questions, print the integer $X$ you deduced in the following format.
$!\ X$
However, if you find that the integer $X$ cannot be determined as exactly $1$ possibility within $N$ questions, print the following.
$!$ $-1$The judge then determines whether your answer is correct as follows.
- If the hidden integer $X$ is one that cannot be determined as exactly $1$ possibility within $N$ questions
- If the hidden integer $X$ is one that can be determined as exactly $1$ possibility within $N$ questions
Your answer is correct only if you correctly report that it cannot be determined; otherwise it is incorrect. Even if you happen to guess the correct value, your answer is incorrect unless you report that it cannot be determined as exactly $1$ possibility.
If you report that it cannot be determined, your answer is incorrect. Otherwise, your answer is correct if the value you deduced and printed equals the integer $X$, and incorrect if it differs.
Sample Interaction
| Input | Output | Explanation |
|---|---|---|
3 | First, you receive the integer $N$ from standard input. | |
? 0 1 | Ask the judge for the product of the 1's digit and the 10's digit. | |
0 | The response is 0. | |
? 0 2 | Ask the judge for the product of the 1's digit and the 100's digit. | |
2 | The response is 2. | |
! -1 | You have concluded that the integer $X$ cannot be determined as exactly $1$ possibility. This conclusion is right, so this is judged as correct. |
Notes
- Each time you print output, add a newline at the end and flush standard input. Otherwise, you may get Time Limit Exceeded.
- After printing your answer, terminate your program normally immediately.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。