AtCoder Regular Contest 179
C
Beware of Overflow
AtCoder
⌀ 1771
原题
← BD →
翻译中…

Problem Statement

翻译中…

This is an interactive problem (where your program interacts with the judge via input and output).

翻译中…

You are given a positive integer $N$.

翻译中…

The judge has a hidden positive integer $R$ and $N$ integers $A_1, A_2, \dots, A_N$. It is guaranteed that $|A_i|\le R$ and $\left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R$.

翻译中…

There is a blackboard on which you can write integers with absolute values not exceeding $R$. Initially, the blackboard is empty.

翻译中…

The judge has written the values $A_1, A_2, \dots, A_N$ on the blackboard in this order. Your task is to make the blackboard contain only one value $\displaystyle\sum_{i=1}^{N}A_i$.

翻译中…

You cannot learn the values of $R$ and $A_i$ directly, but you can interact with the judge up to $25000$ times.

翻译中…

For a positive integer $i$, let $X_i$ be the $i$-th integer written on the blackboard. Specifically, $X_i = A_i$ for $i=1,2,\dots,N$.

翻译中…

In one interaction, you can specify two distinct positive integers $i$ and $j$ and choose one of the following actions:

翻译中…
  • Perform addition. The judge will erase $X_i$ and $X_j$ from the blackboard and write $X_i + X_j$ on the blackboard.
  • $|X_i + X_j| \leq R$ must hold.
  • Perform comparison. The judge will tell you whether $X_i < X_j$ is true or false.
翻译中…

Here, at the beginning of each interaction, the $i$-th and $j$-th integers written on the blackboard must not have been erased.

翻译中…

Perform the interactions appropriately so that after all interactions, the blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$.

翻译中…

The values of $R$ and $A_i$ are determined before the start of the conversation between your program and the judge.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 1000$
  • $1 \leq R \leq 10^9$
  • $|A_i| \leq R$
  • $\left|\displaystyle\sum_{i=1}^{N}A_i\right| \le R$
  • $N$, $R$, and $A_i$ are integers.
翻译中…

Input and Output

翻译中…

This is an interactive problem (where your program interacts with the judge via input and output).

翻译中…

First, read $N$ from Standard Input.

翻译中…

N

翻译中…

Next, repeat the interactions until the blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$.

翻译中…

When performing addition, make an output in the following format to Standard Output. Append a newline at the end. Here, $i$ and $j$ are distinct positive integers.

翻译中…

+ i j

翻译中…

The response from the judge will be given from Standard Input in the following format:

翻译中…

P

翻译中…

Here, $P$ is an integer:

翻译中…
  • If $P \geq N + 1$, it means that the value $X_i + X_j$ has been written on the blackboard, and it is the $P$-th integer written.
  • If $P = -1$, it means that $i$ and $j$ do not satisfy the constraints, or the number of interactions has exceeded $25000$.
翻译中…

When performing comparison, make an output in the following format to Standard Output. Append a newline at the end. Here, $i$ and $j$ are distinct positive integers.

翻译中…

? i j

翻译中…

The response from the judge will be given from Standard Input in the following format:

翻译中…

Q

翻译中…

Here, $Q$ is an integer:

翻译中…
  • If $Q = 1$, it means that $X_i < X_j$ is true.
  • If $Q = 0$, it means that $X_i < X_j$ is false.
  • If $Q = -1$, it means that $i$ and $j$ do not satisfy the constraints, or the number of interactions has exceeded $25000$.
翻译中…

For both types of interactions, if the judge's response is $-1$, your program is already considered incorrect. In this case, terminate your program immediately.

翻译中…

When the blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$, report this to the judge in the following format. This does not count towards the number of interactions. Then, terminate your program immediately.

翻译中…

!

翻译中…

If you make an output in a format that does not match any of the above, -1 will be given from Standard Input.

翻译中…

-1

翻译中…

In this case, your program is already considered incorrect. Terminate your program immediately.

翻译中…

Note

翻译中…
  • For each output, append a newline at the end and flush Standard Output. Otherwise, the verdict may be TLE.
  • Terminate your program immediately after outputting the result (or receiving -1). Otherwise, the verdict will be indeterminate.
  • Extra newlines will be considered as malformed output.
翻译中…

Sample Input and Output

翻译中…

Here is a possible conversation with $N=3, R=10, A_1=-1, A_2=10, A_3=1$.

翻译中…
Input Output Explanation
3 First, the integer $N$ is given.
? 1 2 Perform a comparison.
1 The judge returns $1$ because $X_1\lt X_2\ (-1\lt 10)$.
+ 1 3 Perform an addition.
4 The judge erases $X_1 = -1$ and $X_3 = 1$ from the blackboard and writes $X_1 + X_3 = 0$. This is the fourth integer written.
+ 2 4 Perform an addition.
5 The judge erases $X_2 = 10$ and $X_4 = 0$ from the blackboard and writes $X_2 + X_4 = 10$. This is the fifth integer written.
! The blackboard contains only one value $\displaystyle\sum_{i=1}^{N}A_i$, so report this to the judge.
翻译中…
题目信息
题号
arc179_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。