No.282 Weights and Balances (2)
Problem Statement
Dave, who ends up playing around even during class,
during a science experiment, apparently became curious whether, using all of the weights of various kinds of heaviness,
there is a combination of weights that makes a balance exactly level, and he has been idling away at that.
He found out whether such a level combination exists, but now he no longer knows the masses of the weights and cannot put the weights and balances away, so he is at a loss.
For Dave's sake, arrange the weights in ascending order of mass so that he can concentrate on the class.
There are $N$ weights with pairwise distinct masses and $N$ balances.
The weights and the balances are each numbered from $1$ to $N$.
The mass of each weight is guaranteed to be greater than 0.
You can examine the masses of two weights with a balance.
Use the balances to examine the relations between the weights, and arrange the weights in ascending order of mass.
However, the balance operation can be performed at most $2000$ times. (Added 2015/09/19 10:40)
Input and Output
The number of weights and balances $N(1 \le N \le 500)$ is given on the first line.
The program you submit (hereafter, the answer program) must print two types of queries to standard output.
The queries are the question query, which places weights on the balances and compares their masses, and the answer query, which arranges the weights in ascending order of mass.
The format of a question query is
$?$ $L_1$ $R_1$ ... $L_N$ $R_N$and the format of an answer query is
$!$ $A_1$ $A_2$ ... $A_N$.
$L_i$ is the number of the weight placed on the left side of the $i$-th balance, and $R_i$ is the number of the weight placed on the right side of the $i$-th balance. If nothing is placed, print 0.
You cannot place one weight in two places, nor place two weights in one place. That is, "$?$ $1$ $2$ $1$ $3$" and "$?$ $1$ $1$ $1$ $1$" are regarded as invalid output.
$A_i$ represents the number of the $i$-th lightest weight.
Print each query on 1 line. Do not forget the newline.
When you make a question query, the result is returned to the standard input of the answer program.
The format of the result is
$C_1$ $C_2$ ... $C_N$.
$C_i$ is the tilt of the balance: '$>$' is given if the $i$-th balance tilts to the left, '$=$' if it is level, and '$<$' if it tilts to the right.
A balance tilts toward the side holding the heavier weight. The balances are ideal and have no errors.
See the samples for details.
Flush the output after printing. If you do not flush, the response program may be unable to process the input and the time limit may be exceeded, resulting in a wrong answer. Also, be sure to receive the result after executing a question query. Otherwise, the response program may be unable to process the input, which may cause a wrong answer.
After executing the answer query, terminate your program immediately. Otherwise, you may get a wrong answer as a result of exceeding the judge's time limit.
This problem uses a special judge. Your answer is considered correct if the program terminates within the judge's time limit, the number of questions is at most $2000$ (Added 2015/09/19 10:40), and the weights printed by the answer query are in ascending order of mass.
Notes
- The judge's time limit is 5 seconds, and this includes the reaction time of the response program.
- Printing anything other than the two types of queries results in a wrong answer.
- Output to standard error is regarded as neither a question query, nor an answer query, nor invalid output.
- There is a limit on the number of question queries (Added 2015/09/19 10:40)
- The masses of the weights are pairwise distinct (Added 2015/09/19 11:06)
Example Program
import sys
n = int(input())
print ("? 1 2 0 0")
sys.stdout.flush()
if input() == "> =":
print("! 2 1")
else:
print("! 1 2")
sys.stdout.flush()
Sample
Sample 1
Input
2 > =
Output
? 1 2 0 0 ! 2 1
It is given that there are 2 weights.
The 1st weight was placed on the left side of the 1st balance, and the 2nd weight on its right side. Nothing was placed on the 2nd balance.
The comparison showed that the 1st weight is heavier than the 2nd weight.
The answer given was that arranging the weights in ascending order of mass yields "2 1".
This is correct because the 1st weight is heavier than the 2nd weight.
Sample 2
Input
3 > > = < > = > > > = = = < < <
Output
? 1 2 3 0 0 0 ? 1 3 2 0 0 0 ? 1 0 2 0 3 0 ? 0 0 0 0 0 0 ? 0 1 0 2 0 3 ! 2 1 3
A balance with nothing on it is level.
If a weight is placed on only one side, the balance tilts to that side.
Making a question without placing any weights on the balances is not invalid output.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
紙ぺーぱー