PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000325. Đoán số bí mật 2 (Guess The Number 2)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Đoán số bí mật 2 (Guess The Number 2)

Guess The Number 2

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

This is an interactive problem. Your program communicates with the judge through standard input and output. Before the interaction begins, the judge chooses a hidden integer NN satisfying 1≤N≤1091\le N\le10^9. Its value is not given directly to your program.

The interaction has exactly two phases.

Phase 1 — Specify a mapping. Choose an integer MM such that 1≤M≤1101\le M\le110, then output a sequence A1,A2,…,AMA_1,A_2,\ldots,A_M with 1≤Ai≤M1\le A_i\le M for every 1≤i≤M1\le i\le M. This sequence defines a function ff over {1,2,…,M}\{1,2,\ldots,M\} by f(i)=Aif(i)=A_i.

The function ff need not be a permutation: repeated values in AA are permitted.

Phase 2 — Receive a response and guess. The judge responds with B1,B2,…,BMB_1,B_2,\ldots,B_M. For each index ii, Bi=fN(i)B_i=f^N(i) is the result of applying ff exactly NN times starting at ii. Using BB and the mapping AA you selected, you must identify and print the exact hidden integer NN.

Terminate immediately after printing your guess. If you output invalid data, the judge may print -1 and terminate the interaction; your program must stop if it receives this signal.

Input

Initially, no value of NN and no ordinary input line are provided to your program.

After your program outputs MM and the sequence AA, the judge sends one line containing exactly MM integers B1,B2,…,BMB_1,B_2,\ldots,B_M, in increasing index order; every element belongs to [1,M][1,M].

The response is determined by the mapping you output and the hidden integer NN.

Output

First, output one line containing the integer MM.

Next, output one line containing exactly MM integers A1,A2,…,AMA_1,A_2,\ldots,A_M.

Flush standard output after these two lines before attempting to read the judge's response BB.

After reading all elements of BB, output one line containing your guess for NN, flush the output stream, and terminate.

Do not print prompts, debugging messages, or any unrelated text to standard output.

Subtasks

  • Subtask 1 (20 points): The hidden integer satisfies 1≤N≤1001\le N\le100; your program must choose 1≤M≤1101\le M\le110 and ensure 1≤Ai≤M1\le A_i\le M for every 1≤i≤M1\le i\le M.
  • Subtask 2 (30 points): The hidden integer satisfies 1≤N≤1061\le N\le10^6; your program must choose 1≤M≤1101\le M\le110 and ensure 1≤Ai≤M1\le A_i\le M for every 1≤i≤M1\le i\le M.
  • Subtask 3 (50 points): The hidden integer satisfies 1≤N≤1091\le N\le10^9; your program must choose 1≤M≤1101\le M\le110 and ensure 1≤Ai≤M1\le A_i\le M for every 1≤i≤M1\le i\le M.

Examples

Example 1 — A sample interaction

The judge has chosen N=2N=2. This value is shown only to explain the example: your program does not receive N=2N=2 as input.

Your program's first output:

4
2 3 4 4

The judge's response:

3 4 4 4

Your program's final output:

2

Explanation

The sequence A=(2,3,4,4)A=(2,3,4,4) defines f(1)=2f(1)=2, f(2)=3f(2)=3, f(3)=4f(3)=4, and f(4)=4f(4)=4.

Since the judge selected N=2N=2, each value is transformed by applying ff twice:

  • Starting at 11: 1→2→31\to2\to3, hence B1=3B_1=3.
  • Starting at 22: 2→3→42\to3\to4, hence B2=4B_2=4.
  • Starting at 33: 3→4→43\to4\to4, hence B3=4B_3=4.
  • Starting at 44: 4→4→44\to4\to4, hence B4=4B_4=4.

Therefore, the judge sends 3 4 4 4. Your program identifies the secret as 22 and prints 2 to finish the interaction.

Note: This interaction only demonstrates the protocol. A correct solution for the full range up to 10910^9 must choose a mapping AA that provides enough information to distinguish all possible hidden values.