CF1583D.Omkar and the Meaning of Life

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

It turns out that the meaning of life is a permutation p1,p2,…,pnp_1, p_2, \ldots, p_n of the integers 1,2,…,n1, 2, \ldots, n (2≤n≤1002 \leq n \leq 100). Omkar, having created all life, knows this permutation, and will allow you to figure it out using some queries.

A query consists of an array a1,a2,…,ana_1, a_2, \ldots, a_n of integers between 11 and nn. aa is not required to be a permutation. Omkar will first compute the pairwise sum of aa and pp, meaning that he will compute an array ss where sj=pj+ajs_j = p_j + a_j for all j=1,2,…,nj = 1, 2, \ldots, n. Then, he will find the smallest index kk such that sks_k occurs more than once in ss, and answer with kk. If there is no such index kk, then he will answer with 00.

You can perform at most 2n2n queries. Figure out the meaning of life pp.

Interaction

Start the interaction by reading single integer nn (2≤n≤1002 \leq n \leq 100) — the length of the permutation pp.

You can then make queries. A query consists of a single line "?a1a2…an? \enspace a_1 \enspace a_2 \enspace \ldots \enspace a_n" (1≤aj≤n1 \leq a_j \leq n).

The answer to each query will be a single integer kk as described above (0≤k≤n0 \leq k \leq n).

After making a query do not forget to output 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 documentation for other languages.

To output your answer, print a single line "!p1p2…pn! \enspace p_1 \enspace p_2 \enspace \ldots \enspace p_n" then terminate.

You can make at most 2n2n queries. Outputting the answer does not count as a query.

Hack Format

To hack, first output a line containing nn (2≤n≤1002 \leq n \leq 100), then output another line containing the hidden permutation p1,p2,…,pnp_1, p_2, \ldots, p_n of numbers from 11 to nn.

事实证明,生命的意义是一个 1,2,…,n1, 2, \ldots, n 的排列 p1,p2,…,pnp_1, p_2, \ldots, p_n(其中 2≤n≤1002 \leq n \leq 100)。奥姆卡尔(Omkar)创造了全部生命,因此他知道这个排列,并允许你通过若干次查询来推断出它。

一次查询由一个长度为 nn 的数组 a1,a2,…,ana_1, a_2, \ldots, a_n 构成,其中每个 aja_j 是介于 11 和 nn 之间的整数(aa 不必是排列)。奥姆卡尔首先计算 aa 与 pp 的逐项和,即构造一个数组 ss,使得对所有 j=1,2,…,nj = 1, 2, \ldots, n,均有 sj=pj+ajs_j = p_j + a_j。然后,他找出最小的下标 kk,使得 sks_k 在数组 ss 中出现次数超过一次,并将该 kk 作为回答返回;若不存在这样的 kk,则回答为 00。

你最多可进行 2n2n 次查询。请推断出生命的意义——即排列 pp。

交互流程

首先读入一个整数 nn(2≤n≤1002 \leq n \leq 100),表示排列 pp 的长度。

随后你可以发起查询。每次查询格式为一行:? a_1 a_2 … a_n(其中 1≤aj≤n1 \leq a_j \leq n)。

每次查询的响应为一个整数 kk(0≤k≤n0 \leq k \leq n),其含义如上所述。

每次查询后,请务必输出换行符并刷新输出缓冲区,否则将收到 “Idleness limit exceeded” 错误。为此,请使用以下方式:

  • C++ 中使用 fflush(stdout) 或 cout.flush();
  • Java 中使用 System.out.flush();
  • Pascal 中使用 flush(output);
  • Python 中使用 stdout.flush();
  • 其他语言请查阅相应文档。

当你得出答案后,请输出一行:! p_1 p_2 … p_n,然后终止程序。

你最多可进行 2n2n 次查询。输出最终答案不计入查询次数。

Hack 格式

用于 Hack 时,首先输出一行包含整数 nn(2≤n≤1002 \leq n \leq 100),然后输出另一行,包含隐藏的排列 p1,p2,…,pnp_1, p_2, \ldots, p_n(由 11 到 nn 的整数组成)。

输入输出样例

  • 输入#1

    5
    
    2
    
    0
    
    1

    输出#1

    ? 4 4 2 3 2
    
    ? 3 5 1 5 5
    
    ? 5 2 4 3 1
    
    ! 3 2 1 5 4

说明/提示

In the sample, the hidden permutation pp is [3,2,1,5,4][3, 2, 1, 5, 4]. Three queries were made.

The first query is a=[4,4,2,3,2]a = [4, 4, 2, 3, 2]. This yields s=[3+4,2+4,1+2,5+3,4+2]=[7,6,3,8,6]s = [3 + 4, 2 + 4, 1 + 2, 5 + 3, 4 + 2] = [7, 6, 3, 8, 6]. 66 is the only number that appears more than once, and it appears first at index 22, making the answer to the query 22.

The second query is a=[3,5,1,5,5]a = [3, 5, 1, 5, 5]. This yields s=[3+3,2+5,1+1,5+5,4+5]=[6,7,2,10,9]s = [3 + 3, 2 + 5, 1 + 1, 5 + 5, 4 + 5] = [6, 7, 2, 10, 9]. There are no numbers that appear more than once here, so the answer to the query is 00.

The third query is a=[5,2,4,3,1]a = [5, 2, 4, 3, 1]. This yields s=[3+5,2+2,1+4,5+3,4+1]=[8,4,5,8,5]s = [3 + 5, 2 + 2, 1 + 4, 5 + 3, 4 + 1] = [8, 4, 5, 8, 5]. 55 and 88 both occur more than once here. 55 first appears at index 33, while 88 first appears at index 11, and 1<31 \lt 3, making the answer to the query 11.

Note that the sample is only meant to provide an example of how the interaction works; it is not guaranteed that the above queries represent a correct strategy with which to determine the answer.

在样例中,隐藏的排列 pp 为 [3,2,1,5,4][3, 2, 1, 5, 4]。共进行了三次查询。

第一次查询为 a=[4,4,2,3,2]a = [4, 4, 2, 3, 2]。由此得到 s=[3+4,2+4,1+2,5+3,4+2]=[7,6,3,8,6]s = [3 + 4, 2 + 4, 1 + 2, 5 + 3, 4 + 2] = [7, 6, 3, 8, 6]。其中仅数字 66 出现超过一次,且首次出现在索引 22 处,因此该查询的答案为 22。

第二次查询为 a=[3,5,1,5,5]a = [3, 5, 1, 5, 5]。由此得到 s=[3+3,2+5,1+1,5+5,4+5]=[6,7,2,10,9]s = [3 + 3, 2 + 5, 1 + 1, 5 + 5, 4 + 5] = [6, 7, 2, 10, 9]。此处没有任何数字出现超过一次,因此该查询的答案为 00。

第三次查询为 a=[5,2,4,3,1]a = [5, 2, 4, 3, 1]。由此得到 s=[3+5,2+2,1+4,5+3,4+1]=[8,4,5,8,5]s = [3 + 5, 2 + 2, 1 + 4, 5 + 3, 4 + 1] = [8, 4, 5, 8, 5]。其中 55 和 88 均出现超过一次。55 首次出现在索引 33 处,而 88 首次出现在索引 11 处,且 1<31 \lt 3,因此该查询的答案为 11。

注意:该样例仅用于说明交互方式;不能保证上述查询构成一种能正确确定答案的有效策略。

输入解题思路,AI测评打分。不知道怎么写?

首页