题库练习 Triangle Platinum?
← 上一题 下一题 →

A15980 | Triangle Platinum?

时间限制1s
内存限制256MB
通过 / 提交0/0

题目描述

This is an interactive problem.

Made in Heaven is a rather curious Stand. Of course, it is (arguably) the strongest Stand in existence, but it is also an ardent puzzle enjoyer. For example, it gave Qtaro the following problem recently:

Made in Heaven has $n$ hidden integers $a_1, a_2, \dots, a_n$ ( $3 \le n \le 5000$ , $1 \le a_i \le 4$ ). Qtaro must determine all the $a_i$ by asking Made in Heaven some queries of the following form:

- In one query Qtaro is allowed to give Made in Heaven three distinct indexes $i$ , $j$ and $k$ ( $1 \leq i, j, k \leq n$ ).
- If $a_i, a_j, a_k$ form the sides of a non-degenerate triangle $^\dagger$ , Made in Heaven will respond with the area of this triangle.
- Otherwise, Made in Heaven will respond with $0$ .

By asking at most $5500$ such questions, Qtaro must either tell Made in Heaven all the values of the $a_i$ , or report that it is not possible to uniquely determine them.

Unfortunately due to the universe reboot, Qtaro is not as smart as Jotaro. Please help Qtaro solve Made In Heaven's problem.

—————————————————————— $^\dagger$ Three positive integers $a, b, c$ are said to form the sides of a non-degenerate triangle if and only if all of the following three inequalities hold:

- $a+b > c$ ,
- $b+c > a$ ,
- $c+a > b$ .

输入格式

无

输出格式

The interaction begins with reading $n$ ( $3 \le n \le 5000$ ), the number of hidden integers.

To ask a question corresponding to the triple $(i, j, k)$ ( $1 \leq i < j < k \leq n$ ), output "? $i$ $j$ $k$ " without quotes. Afterward, you should read a single integer $s$ .

- If $s = 0$ , then $a_i$ , $a_j$ , and $a_k$ are not the sides of a non-degenerate triangle.
- Otherwise, $s = 16 \Delta^2$ , where $\Delta$ is the area of the triangle. The area is provided in this format for your convenience so that you need only take integer input.

If the numbers $a_i$ cannot be uniquely determined print "! $-1$ " without quotes. On the other hand, if you have determined all the values of $a_i$ print "! $a_1$ $a_2$ $\dots$ $a_n$ " on a single line.

The interactor is non-adaptive. The hidden array $a_1, a_2, \dots, a_n$ is fixed beforehand and is not changed during the interaction process.

After printing a query do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

- fflush(stdout) or cout.flush() in C++;
- System.out.flush() in Java;
- flush(output) in Pascal;
- stdout.flush() in Python;
- see the documentation for other languages.

Hacks

You can hack a solution with the following input format.

The first line contains a single integer $n$ ( $3 \le n \le 5000$ ) — the number of hidden integers.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ( $1 \le a_i \le 4$ ) — the hidden array.

输入输出样例

输入 #1
3

63
输出 #1
? 1 2 3

! -1
输入 #2
6

0

0

0

63

15

135
输出 #2
? 1 2 3

? 2 3 4

? 4 5 6

? 1 5 6

? 3 5 6

? 1 2 4

! 3 2 1 4 2 2
输入 #3
15

3

3

3

3

3

0
输出 #3
? 1 2 3

? 4 6 7

? 8 9 10

? 11 12 13

? 13 14 15

? 4 5 6

! -1
输入 #4
15

3

15

0

3

3

3
输出 #4
? 1 2 3

? 3 4 5

? 4 5 6

? 7 8 9

? 10 11 12

? 13 14 15

! 1 1 1 2 2 4 1 1 1 1 1 1 1 1 1 1
输入 #5
10

3

48

3

48

63

0
输出 #5
? 1 3 5

? 4 6 8

? 1 5 9

? 6 8 10

? 4 2 6

? 7 10 8

! 1 3 1 2 1 2 4 2 1 2
C++ 编辑器
输入
输出