QOJ.ac

QOJ

Límite de tiempo: 2.0 s Límite de memoria: 1024 MB Puntuación total: 100 Interactivo

#17720. 如何验证这样一个程序

Estadísticas

这是一个交互式问题。

KUPC-kun 写了一个解决以下问题的程序:

给定一棵拥有 $N$ 个顶点的树 $T = (V, E)$。

对于 $T$ 中一个长度为 $k$ 的顶点序列 $\{a_1, \dots, a_k\}$,其得分定义如下。

  • 设 $d(u, v)$ 为树 $T$ 中顶点 $u$ 和 $v$ 之间路径上的边数。则该序列的得分为: $$\prod_{i=1}^k d(a_i, a_{(i \bmod k)+1})$$

给定 $V$ 的一个子集 $S$。对于每个 $1 \le k \le N$,求出以下值 $q_k$。

  • 所有元素均属于 $S$ 且长度为 $k$ 的顶点序列 $\{a_1, \dots, a_k\}$ 的得分之和,对 $2^{61} - 1$ 取模。

KUPC-kun 预先秘密保存了树 $T$ 的信息,并持续将 $T$ 作为输入传给该程序。

你需要在上述程序的帮助下恢复树中所有叶子的信息。设树的顶点数为 $N$,你最多可以进行 $N$ 次询问。

  • 选择 $V$ 的一个子集 $S$,并获取该程序的输出。

假设 KUPC-kun 的程序是正确的,请通过询问获得的信息确定树 $T$ 中包含的所有叶子。

评测机是非适应性(non-adaptive)的,即树 $T$ 在交互开始前就已经确定。

交互格式

首先,从标准输入读入 $N$。($2 \le N \le 50$)

对于每次询问,向标准输出以下列格式输出:

? s1s2...sN

这里,$s_1s_2 \cdots s_N$ 是一个长度为 $N$ 的字符串,表示子集 $S$。如果 $i \in S$,则 $s_i = 1$;如果 $i \notin S$,则 $s_i = 0$。

作为响应,你将从标准输入读入以下内容:

q1 q2 ... qN

一旦你确定了所有的叶子,请以下列格式输出你的答案:

! t1t2...tN

这里,$t_1t_2 \cdots t_N$ 是一个长度为 $N$ 的字符串。如果 $i$ 是叶子,则 $t_i = 1$;如果 $i$ 不是叶子,则 $t_i = 0$。

输出答案后,请立即终止你的程序。

每次输出后,请务必换行并清空标准输出缓冲区(flush)。

样例

输入样例 1

5
0 8 0 32 0
0 44 108 968 3960
0 0 0 0 0
0 76 348 3336 22200

输出样例 1

? 00101
? 11001
? 10000
? 11111
! 11001

说明

对于第一个样例,评测机秘密保存的树的边集为 $(1, 3), (2, 3), (3, 4), (4, 5)$。

在第一次询问中,$S = \{3, 5\}$。

注意 $d(3, 3) = 0$,$d(3, 5) = d(5, 3) = 2$,$d(5, 5) = 0$。

例如,存在以下 $4$ 个元素属于 $S$ 且长度为 $2$ 的顶点序列 $a$:

  • 如果 $a = (3, 3)$,则该序列的得分为 $d(3, 3) \times d(3, 3) = 0 \times 0 = 0$
  • 如果 $a = (3, 5)$,则该序列的得分为 $d(3, 5) \times d(5, 3) = 2 \times 2 = 4$
  • 如果 $a = (5, 3)$,则该序列的得分为 $d(5, 3) \times d(3, 5) = 2 \times 2 = 4$
  • 如果 $a = (5, 5)$,则该序列的得分为 $d(5, 5) \times d(5, 5) = 0 \times 0 = 0$

评测机对 $q_2$ 的响应为 $8$,这是 $0 + 4 + 4 + 0$ 除以 $2^{61} - 1$ 的余数。

通过对其他序列长度进行类似的计算,我们得到评测机的响应为 0 8 0 32 0

这棵树的叶子节点为顶点 $1, 2, 5$,输出 ! 11001 正确完成了对叶子的识别。

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1529EditorialOpen题解jiangly2026-04-15 16:04:40View

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.