D. Hongcow's Game

Codeforces
IDCF745D
Time3000ms
Memory256MB
Difficulty
bitmasksdivide and conquerinteractive
English · Original
Chinese · Translation
Formal · Original
**This is an interactive problem. In the interaction section below you will see the information about flushing the output.** In this problem, you will be playing a game with Hongcow. How lucky of you! Hongcow has a hidden _n_ by _n_ matrix _M_. Let _M__i_, _j_ denote the entry _i_\-th row and _j_\-th column of the matrix. The rows and columns are labeled from 1 to _n_. The matrix entries are between 0 and 109. In addition, _M__i_, _i_ = 0 for all valid _i_. Your task is to find the minimum value along each row, excluding diagonal elements. Formally, for each _i_, you must find . To do this, you can ask Hongcow some questions. A question consists of giving Hongcow a subset of distinct indices {_w_1, _w_2, ..., _w__k_}, with 1 ≤ _k_ ≤ _n_. Hongcow will respond with _n_ integers. The _i_\-th integer will contain the minimum value of _min_1 ≤ _j_ ≤ _k__M__i_, _w__j_. You may only ask Hongcow at most 20 questions — he thinks you only need that many questions answered. When you are ready to answer, print out a single integer  - 1 on its own line, then _n_ integers on the next line. The _i_\-th integer should be the minimum value in the _i_\-th row of the matrix, excluding the _i_\-th element. Do not forget to flush the final answer as well. Printing the answer does not count as asking a question. You will get _Wrong Answer_ verdict if * Your question or answers are not in the format described in this statement. * You ask strictly more than 20 questions. * Your question contains duplicate indices. * The value of _k_ in your question does not lie in the range from 1 to _n_, inclusive. * Your final answer is not correct. You will get _Idleness Limit Exceeded_ if you don't print anything or if you forget to flush the output, including for the final answer (more info about flushing output below). ## Input The first line of input will contain a single integer _n_ (2 ≤ _n_ ≤ 1, 000). ## Output To print the final answer, print out the string _\-1_ on its own line. Then, the next line should contain _n_ integers. The _i_\-th integer should be the minimum value of the _i_\-th row of the matrix, excluding elements on the diagonal. **Do not forget to flush your answer!** [samples] ## Interaction To ask a question, print out a single integer _k_ on its own line, denoting the size of your subset. Then, the next line should contain _k_ integers _w_1, _w_2, ... _w__k_. Note, you must flush your output to get a response. Hongcow will respond by printing out a line with _n_ integers. The _i_\-th integer in this line represents the minimum value of _M__i_, _w__j_ where _j_ is between 1 and _k_. You may only ask a question at most 20 times, otherwise, you will get _Wrong Answer_. To flush you can use (just after printing an integer and end-of-line): * _fflush(stdout)_ in C++; * _System.out.flush()_ in Java; * _stdout.flush()_ in Python; * _flush(output)_ in Pascal; * See the documentation for other languages. **Hacking** To hack someone, use the following format n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} Of course, contestant programs will not be able to see this input. ## Note In the first sample, Hongcow has the hidden matrix \[ \[0, 3, 2\], \[5, 0, 7\], \[4, 8 ,0\], \] Here is a more readable version demonstrating the interaction. The column on the left represents Hongcow, while the column on the right represents the contestant. 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 For the second sample, it is possible for off-diagonal elements of the matrix to be zero.
*这是一个交互式问题。在下面的交互部分,你将看到有关刷新输出的信息。* 在这个问题中,你将和 Hongcow 玩一个游戏。你真幸运! Hongcow 有一个隐藏的 #cf_span[n] × #cf_span[n] 矩阵 #cf_span[M]。令 #cf_span[Mi, j] 表示矩阵的第 #cf_span[i] 行第 #cf_span[j] 列的元素。行和列的编号从 #cf_span[1] 到 #cf_span[n]。 矩阵元素的值在 #cf_span[0] 到 #cf_span[109] 之间。此外,对于所有有效的 #cf_span[i],有 #cf_span[Mi, i = 0]。你的任务是找出每行中除对角线元素外的最小值。形式上,对于每个 #cf_span[i],你必须找到 。 为了完成这个任务,你可以向 Hongcow 提问。 一个提问由给出一个互不相同的下标子集 #cf_span[{w1, w2, ..., wk}] 组成,其中 #cf_span[1 ≤ k ≤ n]。Hongcow 会返回 #cf_span[n] 个整数。第 #cf_span[i] 个整数表示 #cf_span[min1 ≤ j ≤ kMi, wj] 的最小值。 你最多只能向 Hongcow 提问 #cf_span[20] 次——他认为你只需要这么多问题的答案。 当你准备好给出答案时,请单独输出一个整数 #cf_span[ - 1],然后在下一行输出 #cf_span[n] 个整数。第 #cf_span[i] 个整数应为矩阵第 #cf_span[i] 行中除去第 #cf_span[i] 个元素的最小值。同样,请不要忘记刷新最终答案的输出。输出答案不计入提问次数。 如果你出现以下情况,将获得 _Wrong Answer_: 输入的第一行包含一个整数 #cf_span[n](#cf_span[2 ≤ n ≤ 1, 000])。 要输出最终答案,请单独输出字符串 _-1_,然后下一行输出 #cf_span[n] 个整数。第 #cf_span[i] 个整数应为矩阵第 #cf_span[i] 行中除去对角线元素的最小值。*不要忘记刷新你的答案!* 要提问,请单独输出一个整数 #cf_span[k],表示你子集的大小。然后下一行输出 #cf_span[k] 个整数 #cf_span[w1, w2, ... wk]。注意,你必须刷新输出才能获得回应。 Hongcow 会返回一行包含 #cf_span[n] 个整数。该行的第 #cf_span[i] 个整数表示 #cf_span[Mi, wj] 的最小值,其中 #cf_span[j] 在 #cf_span[1] 到 #cf_span[k] 之间。 你最多只能提问 #cf_span[20] 次,否则将获得 _Wrong Answer_。 要刷新输出,可以在输出一个整数并换行后使用: *黑客* 要黑客攻击某人,请使用以下格式: 当然,参赛程序无法看到此输入。 在第一个样例中,Hongcow 的隐藏矩阵为 以下是一个更易读的交互演示。左侧列代表 Hongcow,右侧列代表参赛者。 在第二个样例中,矩阵的非对角线元素可能为零。 ## Input 输入的第一行包含一个整数 #cf_span[n](#cf_span[2 ≤ n ≤ 1, 000])。 ## Output 要输出最终答案,请单独输出字符串 _-1_,然后下一行输出 #cf_span[n] 个整数。第 #cf_span[i] 个整数应为矩阵第 #cf_span[i] 行中除去对角线元素的最小值。*不要忘记刷新你的答案!* [samples] ## Interaction 要提问,请单独输出一个整数 #cf_span[k],表示你子集的大小。然后下一行输出 #cf_span[k] 个整数 #cf_span[w1, w2, ... wk]。注意,你必须刷新输出才能获得回应。Hongcow 会返回一行包含 #cf_span[n] 个整数。该行的第 #cf_span[i] 个整数表示 #cf_span[Mi, wj] 的最小值,其中 #cf_span[j] 在 #cf_span[1] 到 #cf_span[k] 之间。你最多只能提问 #cf_span[20] 次,否则将获得 _Wrong Answer_。要刷新输出,可以在输出一个整数并换行后使用: _fflush(stdout)_ 在 C++ 中; _System.out.flush()_ 在 Java 中; _stdout.flush()_ 在 Python 中; _flush(output)_ 在 Pascal 中; 请参阅其他语言的文档。 *黑客* 要黑客攻击某人,请使用以下格式: n M_{1,1} M_{1,2} ... M_{1,n} M_{2,1} M_{2,2} ... M_{2,n} ... M_{n,1} M_{n,2} ... M_{n,n} 当然,参赛程序无法看到此输入。 ## Note 在第一个样例中,Hongcow 的隐藏矩阵为 [ [0, 3, 2], [5, 0, 7], [4, 8 ,0], ] 以下是一个更易读的交互演示。左侧列代表 Hongcow,右侧列代表参赛者。 3 3 1 2 3 0 0 0 1 3 2 7 0 2 1 2 0 0 4 1 2 3 0 8 1 1 0 5 4 -1 2 5 4 在第二个样例中,矩阵的非对角线元素可能为零。
**Definitions:** - Let $ M \in \mathbb{Z}^{n \times n} $ be a hidden matrix with $ M_{i,i} = 0 $ for all $ i \in \{1, 2, \dots, n\} $, and $ 0 \leq M_{i,j} \leq 10^9 $ for all $ i \neq j $. **Given/Constraints:** - $ 2 \leq n \leq 1000 $ - You may query at most 20 times. - Each query: submit a subset $ W = \{w_1, w_2, \dots, w_k\} \subseteq \{1, 2, \dots, n\} $, $ 1 \leq k \leq n $. - Response to query $ W $: for each row $ i \in \{1, \dots, n\} $, return $ \min_{j \in W} M_{i,j} $. **Objective:** - For each row $ i \in \{1, \dots, n\} $, compute $ \min_{j \neq i} M_{i,j} $. **Output:** - Print $-1$, then $ n $ integers: $ \min_{j \neq i} M_{i,j} $ for $ i = 1 $ to $ n $.
Samples
Input #1
3
0 0 0
2 7 0
0 0 4
3 0 8
0 5 4
Output #1
3
1 2 3
1
3
2
1 2
1
2
1
1
-1
2 5 4
Input #2
2
0 0
0 0
Output #2
1
2
1
1
-1
0 0
API Response (JSON)
{
  "problem": {
    "name": "D. Hongcow's Game",
    "description": {
      "content": "**This is an interactive problem. In the interaction section below you will see the information about flushing the output.** In this problem, you will be playing a game with Hongcow. How lucky of you",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 3000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF745D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "**This is an interactive problem. In the interaction section below you will see the information about flushing the output.**\n\nIn this problem, you will be playing a game with Hongcow. How lucky of you...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "*这是一个交互式问题。在下面的交互部分,你将看到有关刷新输出的信息。*\n\n在这个问题中,你将和 Hongcow 玩一个游戏。你真幸运!\n\nHongcow 有一个隐藏的 #cf_span[n] × #cf_span[n] 矩阵 #cf_span[M]。令 #cf_span[Mi, j] 表示矩阵的第 #cf_span[i] 行第 #cf_span[j] 列的元素。行和列的编号从 #cf_span[1...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions:**\n- Let $ M \\in \\mathbb{Z}^{n \\times n} $ be a hidden matrix with $ M_{i,i} = 0 $ for all $ i \\in \\{1, 2, \\dots, n\\} $, and $ 0 \\leq M_{i,j} \\leq 10^9 $ for all $ i \\neq j $.\n\n**Given/C...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments