QOJ.ac

QOJ

时间限制: 2.0 s 内存限制: 2048 MB 总分: 100 交互

#18234. 比较后缀

统计

评测程序拥有一个长度为 $n$ 且仅由小写拉丁字母(a–z)组成的隐藏字符串 $S$。你无法直接访问该字符串。在开始时,你只会被告知其长度 $n$。

你的任务是在限制的查询次数内,确定所有 $n$ 个后缀的顺序。

对于整数 $k$ ($1 \le k \le n$),令 $S(k)$ 表示从第 $k$ 个字符开始的 $S$ 的后缀。特别地,$S(1) = S$。

在单次查询中,你需要指定两个不同的整数 $i$ 和 $j$。评测程序会按字典序比较 $S(i)$ 和 $S(j)$,并向你返回 $S(i) < S(j)$ 还是 $S(i) > S(j)$。请注意,由于所有后缀都是互不相同的,因此当 $i \ne j$ 时绝不会出现平局。

求一个 $(1, 2, \dots, n)$ 的排列 $(p_1, p_2, \dots, p_n)$,使得 $S(p_1) < S(p_2) < \dots < S(p_n)$。

交互

输入的第一行包含一个整数 $n$ ($2 \le n \le 1000$)。

要进行查询,你的程序应当输出一行格式为 query i j ($1 \le i \le n$;$1 \le j \le n$;$i \ne j$) 的内容。随后,你可以从输入中读取一行,内容为 firstsecond。读入 first 表示 $S(i) < S(j)$,而读入 second 表示 $S(i) > S(j)$。

一旦你确定了后缀的顺序,你的程序应当输出一行格式为 answer p1 p2 ... pn 的内容。在此之后,交互停止,你的程序应当终止且不产生额外的输出。

你的程序最多可以进行 $6260$ 次查询。如果你的程序进行了超过 $6260$ 次查询,将被判定为“Wrong Answer”(答案错误)。

保证隐藏的字符串 $S$ 仅由小写字母(a–z)组成。

关于交互式评测的说明:

  • 评测是非适应性(non-adversarial)的,这意味着字符串 $S$ 是预先确定的,而不是根据你的查询动态生成的。
  • 请不要忘记在输出后刷新输出缓冲区。详情请参阅“Judging Details”文档。
  • 我们为你提供了一个用于本地测试的命令行工具,以及与样例交互对应的输入文件。你可以从 DOMjudge 下载这些文件。该工具的顶部有注释解释其用法。

样例

输入样例 1

4
first
second
first

输出样例 1

query 2 1
query 2 4
query 1 3
answer 4 2 1 3

说明 1

在本样例中,假设 $S = \text{icpc}$。四个后缀的顺序为 $S(4) < S(2) < S(1) < S(3)$,因为 $\text{c} < \text{cpc} < \text{icpc} < \text{pc}$。

在第一次和第三次查询中,由于 $S(2) < S(1)$ 且 $S(1) < S(3)$,因此返回 first。在第二次查询中,由于 $S(2) > S(4)$,因此返回 second。通过这些响应,你可以确定它们的顺序。

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.