CF1847E.Triangle Platinum?

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 nn hidden integers a1,a2,,ana_1, a_2, \dots, a_n ( 3n50003 \le n \le 5000 , 1ai41 \le a_i \le 4 ). Qtaro must determine all the aia_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 ii , jj and kk ( 1i,j,kn1 \leq i, j, k \leq n ).
  • If ai,aj,aka_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 00 .

By asking at most 55005500 such questions, Qtaro must either tell Made in Heaven all the values of the aia_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,ca, 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>ca+b > c ,
  • b+c>ab+c > a ,
  • c+a>bc+a > b .

输入格式

输出格式

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

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

  • If s=0s = 0 , then aia_i , aja_j , and aka_k are not the sides of a non-degenerate triangle.
  • Otherwise, s=16Δ2s = 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 aia_i cannot be uniquely determined print "! 1-1 " without quotes. On the other hand, if you have determined all the values of aia_i print "! a1a_1 a2a_2 \dots ana_n " on a single line.

The interactor is non-adaptive. The hidden array a1,a2,,ana_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 nn ( 3n50003 \le n \le 5000 ) — the number of hidden integers.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai41 \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

说明/提示

In the first example, the interaction process happens as follows:

StdinStdoutExplanation3Read n=3n = 3 . There are 33 hidden integers? 1 2 3Ask for the area formed by a1a_1 , a2a_2 and a3a_3 63Received 16Δ2=6316\Delta^2 = 63 . So the area Δ=63161.984313\Delta = \sqrt{\frac{63}{16}} \approx 1.984313 ! -1Answer that there is no unique array satisfying the queries.From the area received, we can deduce that the numbers that forms the triangle are either ( 44 , 44 , 11 ) or ( 33 , 22 , 22 ) (in some order). As there are multiple arrays of numbers that satisfy the queries, a unique answer cannot be found.

In the second example, the interaction process happens as follows:

StepStdinStdoutExplanation16Read n=6n = 6 . There are 66 hidden integers2? 1 2 3Ask for the area formed by a1a_1 , a2a_2 and a3a_3 30Does not form a non-degenerate triangle4? 2 3 4Ask for the area formed by a2a_2 , a3a_3 and a4a_4 50Does not form a non-degenerate triangle6? 4 5 6Ask for the area formed by a4a_4 , a5a_5 and a6a_6 70Does not form a non-degenerate triangle8? 1 5 6Ask for the area formed by a1a_1 , a5a_5 and a6a_6 963Received 16Δ2=6316\Delta^2 = 63 . So the area Δ=63161.984313\Delta = \sqrt{\frac{63}{16}} \approx 1.984313 10? 3 5 6Ask for the area formed by a3a_3 , a5a_5 and a6a_6 1115Received 16Δ2=1516\Delta^2 = 15 . So the area Δ=15160.968245\Delta = \sqrt{\frac{15}{16}} \approx 0.968245 12? 1 2 4Ask for the area formed by a3a_3 , a5a_5 and a6a_6 13135Received 16Δ2=13516\Delta^2 = 135 . So the area Δ=135162.904738\Delta = \sqrt{\frac{135}{16}} \approx 2.904738 14! 3 2 1 4 2 2A unique answer is found, which is a=[3,2,1,4,2,2]a = [3, 2, 1, 4, 2, 2] .From steps 1010 and 1111 , we can deduce that the the multiset {a3,a5,a6}\left\{a_3, a_5, a_6\right\} must be {2,2,1}\left\{2, 2, 1\right\} .

From steps 88 and 99 , the multiset {a1,a5,a6}\left\{a_1, a_5, a_6\right\} must be either {4,4,1}\left\{4, 4, 1\right\} or {3,2,2}\left\{3, 2, 2\right\} .

As {a3,a5,a6}\left\{a_3, a_5, a_6\right\} and {a1,a5,a6}\left\{a_1, a_5, a_6\right\} share a5a_5 and a6a_6 , we conclude that a5=a6=2a_5 = a_6 = 2 , as well as a1=3a_1 = 3 , a3=1a_3 = 1 .

From steps 66 and 77 , we know that a5=a6=2a_5 = a_6 = 2 , and a4a_4 , a5a_5 and a6a_6 cannot form a non-degenerate triangle, hence a4=4a_4 = 4 .

With all the known information, only a2=2a_2 = 2 satisfies the queries made in steps 22 , 33 , 44 , 55 , 1212 and 1313 .

In the third example, one array that satisfies the queries is [1,1,1,1,3,1,1,1,1,1,1,1,1,1,1][1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1] .

首页