#P16559. [ICPC 2026 APC] Compare Suffixes
[ICPC 2026 APC] Compare Suffixes
题目描述
The judge program possesses a hidden string of length consisting only of lowercase Latin letters (a–z). You cannot access the string. At the start, only the length is given to you.
Your task is to determine the order of all suffixes using a limited number of queries.
For an integer ( ), let denote the suffix of starting at the -th character. In particular, .
In a single query, you specify two distinct integers and . The judge program compares and lexicographically and returns whether or to you. Note that ties never occur for because all suffixes are distinct.
Find a permutation of such that .
输入格式
The first line of input contains the integer ().
To issue a query, your program should write a line of the form "query " (). After that, an input line containing first or second becomes available. A line containing first means , while a line containing second means .
Once you determine the order of the suffixes, your program should write a line of the form "answer ". After that, the interaction stops and your program should terminate without extra output.
Your program may issue at most queries. If your program issues more than queries, it will be judged as "Wrong Answer."
It is guaranteed that the hidden string consists only of lowercase letters (a–z).
Notes on interactive judging:
- The evaluation is non-adversarial, meaning that the string is chosen in advance rather than in response to your queries.
- Do not forget to flush output buffers after writing.
- You are provided with a command-line tool for local testing, together with input files corresponding to the sample interactions. You can download these files. The tool has comments at the top to explain its use.
4
first
second
first
query 2 1
query 2 4
query 1 3
answer 4 2 1 3
提示
Explanation for the sample interaction #1
In this sample, is assumed. The order of four suffixes is because $\texttt{c} \lt \texttt{cpc} \lt \texttt{icpc} \lt \texttt{pc}$ .
In the first and third query, first is returned because and . In the second query, second is returned because . With these responses, you can determine the ordering.