第 233 场 AtCoder Regular Contest++
A
奇怪的子集和
Strange Subset Sum
AtCoder
⌀ 1767
原题
←B →

奇怪的子集和AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

This is an interactive problem (where your program interacts with the judge system via Standard Input and Output).

这是一道交互题(你的程序需要通过标准输入和标准输出与评测系统进行交互)。AI (CI翻译)

You are given a positive integer $N$.

给定一个正整数 $N$。AI (CI翻译)

For a set $X$ of positive integers, a subset of $X$ whose sum is $N$ is called a special subset of $X$.

对于一个正整数集合 $X$,如果 $X$ 的某个子集的元素之和为 $N$,则称该子集为 $X$ 的特殊子集。AI (CI翻译)

The judge system has a hidden set $A$ that satisfies all of the following conditions, but you cannot directly know the values of the elements of $A$.

评测系统有一个满足以下所有条件的隐藏集合 $A$,但你无法直接得知 $A$ 中各元素的值。AI (CI翻译)

  • $|A|=\left\lfloor\frac{N}{2}\right\rfloor$
  • Every element of $A$ is an integer between $1$ and $N-1$, inclusive.
  • $|A|=\left\lfloor\frac{N}{2}\right\rfloor$
  • $A$ 中的每个元素都是一个介于 $1$ 和 $N-1$(包含两端)的整数。
AI (CI翻译)

You may ask the judge system the following question at most $\left\lfloor\frac{3N}{4}\right\rfloor$ times.

你最多可以向评测系统询问 $\left\lfloor\frac{3N}{4}\right\rfloor$ 次以下问题。AI (CI翻译)

  • Choose an integer $a$ between $1$ and $N-1$, inclusive, and ask whether $a$ is contained in $A$.
  • 选择一个介于 $1$ 和 $N-1$(包含两端)的整数 $a$,询问 $a$ 是否属于 $A$。
AI (CI翻译)

Determine whether the hidden set $A$ has a special subset, and if it does, find the minimum number of elements in a special subset.

判断隐藏集合 $A$ 是否有特殊子集;如果有,求特殊子集中元素个数的最小值。AI (CI翻译)

Solve $T$ test cases for each input.

对于每组输入,需要解决 $T$ 组测试用例。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq T \leq 5 \times 10^4$
  • $4 \leq N \leq 2 \times 10^5$
  • The sum of $N$ over all test cases is at most $2 \times 10^5$.
  • All input values are integers.
  • $1 \leq T \leq 5 \times 10^4$
  • $4 \leq N \leq 2 \times 10^5$
  • 所有测试用例的 $N$ 之和不超过 $2 \times 10^5$。
  • 所有输入值均为整数。
AI (CI翻译)

Interaction

交互

AI (CI翻译)

This is an interactive problem (where your program interacts with the judge system via Standard Input and Output).

这是一道交互题(你的程序需要通过标准输入和标准输出与评测系统进行交互)。AI (CI翻译)

First, receive the number of test cases $T$ from Standard Input.

首先,从标准输入读入测试用例数 $T$。AI (CI翻译)

T

T
AI (CI翻译)

Then, $T$ test cases follow. Each test case proceeds as follows.

接下来有 $T$ 组测试用例。每组测试用例如下进行。AI (CI翻译)

Receive the integer $N$ from Standard Input.

从标准输入读入整数 $N$。AI (CI翻译)

N

N
AI (CI翻译)

Then, you may ask at most $\left\lfloor\frac{3N}{4}\right\rfloor$ questions. Print each question to Standard Output in the following format:

之后,你最多可以提出 $\left\lfloor\frac{3N}{4}\right\rfloor$ 次询问。每次询问按照以下格式输出到标准输出:AI (CI翻译)

? a

? a
AI (CI翻译)

Here, $a$ must satisfy the following:

其中 $a$ 必须满足以下条件:AI (CI翻译)

  • $1 \leq a \leq N-1$
  • $a$ is an integer.
  • $1 \leq a \leq N-1$
  • $a$ 是整数。
AI (CI翻译)

In response, Yes is given from Standard Input if $a$ is contained in $A$, and No is given otherwise.

如果 $a$ 属于 $A$,标准输入将返回 Yes;否则返回 No。AI (CI翻译)

However, if $a$ does not satisfy the conditions above, or if the number of questions exceeds $\left\lfloor\frac{3N}{4}\right\rfloor$, -1 is returned.

但是,如果 $a$ 不满足上述条件,或者询问次数超过 $\left\lfloor\frac{3N}{4}\right\rfloor$,则会返回 -1。AI (CI翻译)

If the judge returns -1, your program is already considered incorrect. In this case, terminate your program immediately.

如果评测系统返回 -1,你的程序将被判为错误。此时请立即终止程序。AI (CI翻译)

Let $S=-1$ if $A$ has no special subset; otherwise, let $S$ be the minimum number of elements in a special subset. Once you have found $S$, print it to Standard Output in the following format.

设 $S=-1$ 表示 $A$ 没有特殊子集;否则,设 $S$ 为特殊子集中元素个数的最小值。 找到 $S$ 后,按照以下格式将其输出到标准输出:AI (CI翻译)

! S

! S
AI (CI翻译)

Then, proceed to the next test case if one exists. After processing the last test case, terminate your program immediately.

如果还有下一组测试用例,则继续处理。处理完最后一组测试用例后,立即终止程序。AI (CI翻译)

Note

说明

AI (CI翻译)
  • For each output, add a newline at the end and flush Standard Output. Otherwise, you may receive a TLE verdict.
  • If your program prints output in an incorrect format during the interaction or terminates prematurely, the verdict is indeterminate.
  • After processing the last test case, terminate your program immediately. Otherwise, the verdict is indeterminate.
  • The judge of this problem is not adaptive. The judge fixes the set $A$ for every test case before the interaction.
  • 每次输出后都要换行,并刷新标准输出,否则可能会因 TLE 被判定为超时。
  • 如果程序在交互过程中输出格式错误或提前终止,评测结果将无法确定。
  • 处理完最后一组测试用例后,立即终止程序。否则评测结果将无法确定。
  • 本题的评测器不是自适应的。评测器会在交互开始前,为每组测试用例确定集合 $A$。
AI (CI翻译)

Sample Interaction

样例交互

AI (CI翻译)

The following is a sample interaction for $N=6,A=\lbrace1,2,4\rbrace$. In this case, $\left\lfloor\frac{3N}{4}\right\rfloor=4$, so you may ask at most $4$ questions.

以下是 $N=6,A=\lbrace1,2,4\rbrace$ 时的一段样例交互。在此情况下,$\left\lfloor\frac{3N}{4}\right\rfloor=4$,因此最多可以提出 $4$ 次询问。AI (CI翻译)

Input Output Explanation
1 First, the number of test cases $T$ is given.
6 Then, the integer $N$ is given.
? 2 Ask a question with $a=2$.
Yes $2$ is contained in $A$, so the judge returns Yes.
? 5 Ask a question with $a=5$.
No $5$ is not contained in $A$, so the judge returns No.
? 3 Ask a question with $a=3$.
No $3$ is not contained in $A$, so the judge returns No.
! 2 Now that you know the answer is $2$, print it.
输入 输出 说明
1 首先给出测试用例数 $T$。
6 接下来给出整数 $N$。
? 2 询问 $a=2$。
Yes $2$ 属于 $A$,因此评测系统返回 Yes。
? 5 询问 $a=5$。
No $5$ 不属于 $A$,因此评测系统返回 No。
? 3 询问 $a=3$。
No $3$ 不属于 $A$,因此评测系统返回 No。
! 2 现在已知答案是 $2$,输出该答案。
AI (CI翻译)
题目信息
题号
arc233_a
时间限制
2 s
内存限制
1024 MB

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