QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100 Interactivo

#10614. 零与一

Estadísticas

给定一个由 $0$ 和 $1$ 组成的序列 $a_0, \dots, a_{n-1}$。你不知道该序列的元素,但可以询问任意两个不同位置的元素之和。你的任务是通过尽可能少的问题猜出该序列。

交互

本题为交互题。你可以选择通过库函数或标准输入输出与评测程序进行通信。请选择其中一种方式,不要同时使用两种方法

你的程序不得打开任何文件。程序可以使用标准错误输出(stderr),但请注意这会消耗时间。任何输出到标准输出的额外数据都可能被视为错误答案。

注意:给出的内存和时间限制仅适用于你的解决方案(不包括评测程序)。

选项 1:使用库函数进行通信

在此选项中,你的程序不得使用标准输入输出。

C++ 程序开头需包含: * #include "zerlib.h"

库提供以下函数: int daj_n() – 返回整数 $n$,表示 $0$ 和 $1$ 序列的长度。该函数可调用任意多次。 int suma(int i, int j) – 返回 $a_i + a_j$,其中 $0 \le i, j < n$ 且 $i \neq j$。否则调用将导致错误答案。 * void odpowiedz(std::vector<int> a) – 用于提交结果序列。必须调用且仅调用一次。它接收一个表示结果序列 $a[0], \dots, a[n-1]$ 的 std::vector<int>。如果提交的序列错误或长度不为 $n$,将导致错误答案。调用此函数后必须终止程序。

Python 程序开头需包含: * from zerlib import daj_n, suma, odpowiedz

库提供以下函数: daj_n() -> int – 返回整数 $n$,表示 $0$ 和 $1$ 序列的长度。该函数可调用任意多次。 suma(i : int, j : int) -> int – 返回 $a_i + a_j$,其中 $0 \le i, j < n$ 且 $i \neq j$。否则调用将导致错误答案。 * odpowiedz(a : list[int]) – 用于提交结果序列。必须调用且仅调用一次。它接收一个表示结果序列 $a[0], \dots, a[n-1]$ 的列表。如果提交的序列错误或长度不为 $n$,将导致错误答案。调用此函数后必须终止程序。

选项 2:通过标准输入输出进行通信

标准输入的第一行包含一个整数 $n$,表示未知序列的长度。

要向评测程序提问,需输出两个整数 $i$ 和 $j$,满足 $0 \le i, j < n$ 且 $i \neq j$。如果条件不满足,将导致错误答案。数字应输出到标准输出,以空格分隔并以换行符结束。随后,从标准输入读取一个整数,表示 $a_i + a_j$。

最后,提交结果序列。为此,需在一行中输出 $n$,并在下一行输出 $n$ 个由空格分隔的整数,表示结果序列 $a[0], \dots, a[n-1]$。如果输出的序列错误或长度不为 $n$,将导致错误答案。输出序列后必须终止程序。

C++ 流式输入输出 需包含头文件 #include <iostream>。输出每行后需使用 std::endl

C++ stdio 输入输出 需包含头文件 #include <cstdio>。输出每行后需使用 fflush(stdout)

Python 输出每行后需设置 flush = True

子任务

测试集分为以下子任务:

子任务 数据范围 分值
1 $3 \le n \le 1000$ 50
2 $3 \le n \le 200\,000$ 50

评测程序不需要在交互开始时就生成序列 $a_0, \dots, a_{n-1}$。它可以在交互过程中修改序列元素,只要新元素与之前 suma 函数调用的结果保持一致即可。

设 $m$ 为你的程序在单个测试用例中调用 suma 函数的最大次数,你的解决方案将根据以下比例获得分数(若超过时间限制的一半,分数将相应缩减):

调用次数 得分比例
$m \le n$ 100%
$m = n + 1$ 80%
$m \le n^2 - n$ 50%
$m > n^2 - n$ 0% (判为错误答案)

样例

样例 1

操作 参数 结果 说明
daj_n 5 $n = 5$
suma $i = 0, j = 1$ 1 $a_0 + a_1 = 1$
suma $i = 1, j = 2$ 1 $a_1 + a_2 = 1$
suma $i = 3, j = 4$ 2 $a_3 + a_4 = 2$, 因此 $a_3 = a_4 = 1$
suma $i = 0, j = 3$ 2 $a_0 + a_3 = 2$, 因此 $a_0 = 1$, 进而得出 $a_1 = 0$ 且 $a_2 = 1$
odpowiedz $a = 1, 0, 1, 1, 1$ 使用 $m = 4 \le n = 5$ 次询问得到正确答案,得 100% 分数

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.