#P15496. [ICPC 2025 APC] Minus Operator

[ICPC 2025 APC] Minus Operator

Description

The minus operator on binary values aa and bb is defined by (ab)=1(a - b) = 1 if a=1a = 1 and b=0b = 0; otherwise, (ab)=0(a - b) = 0. Also, the syntax of an expression is defined as follows. Here, x\mathbf{x}, parentheses, and the minus are terminal symbols, and EE is the start symbol.

$$\begin{aligned} E &::=\mathbf{x} \mid (E - E) \end{aligned}$$

The judge program possesses an expression adhering to EE. The expression is hidden from you. At the start, you are only provided with the number of terminal symbols x\mathbf{x} in the expression, denoted by nn.

Your task is to guess the expression by making a limited number of queries.

In a single query, you specify a binary string SS of length nn. The judge program then temporarily replaces each occurrence of the ii-th terminal symbol x\mathbf{x} from the left with SiS_i, for i=1,,ni = 1, \ldots, n, and evaluates the replaced expression based on the definition of the minus operator. After that, the judge program returns the evaluated value to you, which is either 00 or 11.

Interaction

The first line of input contains an integer nn (3n2003 \leq n \leq 200). After reading the integer, your program can start making queries. For each query, your program should write a line of the form "query SS". Here, SS is a binary string of length nn. Each character of SS must be either 00 or 11. In response, an input line containing the evaluated value becomes available.

Your program can make up to 500500 queries. If your program makes more than 500500 queries, it will be judged as "Wrong Answer."

When your program identifies the expression that the judge program possesses, it should write a line of the form "answer TT", where TT is the expression. After that, the interaction stops and your program should terminate.

Under the constraints above, it can be shown that the expression can be uniquely identified.

Notes on interactive judging:

  • The evaluation is non-adversarial, meaning that the expression is chosen in advance rather than in response to your queries.
  • Do not forget to flush output buffers after writing. See the "Judging Details" document for details.
  • You are provided with a command-line tool for local testing, together with input files corresponding to the sample interactions. You can download these files from DOMjudge. The tool has comments at the top to explain its use.
3

0

query 111

answer ((x-x)-x)
4

0

1

query 0000

query 1001

answer ((x-x)-(x-x))

Hint

Explanation for the sample interaction #1

When n=3n = 3, there are only two possible expressions: ((xx)x)((\mathbf{x} - \mathbf{x}) - \mathbf{x}) or (x(xx))(\mathbf{x} - (\mathbf{x} - \mathbf{x})). For a query s=111s = 111, the evaluated values for these expressions are,

  • ((11)1)=(01)=0((1 - 1) - 1) = (0 - 1) = 0, and
  • (1(11))=(10)=1(1 - (1 - 1)) = (1 - 0) = 1.

In this example, the judge program returns 00, indicating that the first expression is the correct one.