#P17578. [JAG 2026 Summer Camp #3] Guess Palindrome
[JAG 2026 Summer Camp #3] Guess Palindrome
Problem Description
Alice has a hidden string of length consisting only of the two characters a and b. Since she likes symmetric strings, it is known that is a palindrome. Your task is to determine by asking Alice the following type of query:
- You provide an arbitrary non-empty string of length at most consisting only of
aandb. - Alice responds with an integer representing the number of occurrences of as a contiguous substring of . Occurrences are counted even if they overlap.
However, to avoid upsetting Alice, you may ask at most queries.
Write a program that determines the hidden string within the given query limit.
Interaction
First, the length of () is given from standard input.
After reading the input, you may start asking queries. To ask a query with a string , print the following format to standard output, where must be a non-empty string of length at most consisting only of a and b.
? T
In response to this query, an integer representing the number of occurrences of as a contiguous substring of is given from standard input.
Once you have determined , print your answer to standard output in the following format.
! S
You may ask at most queries and print the answer exactly once. After printing the answer, your program must terminate immediately.
If your program violates the specified format, exceeds the query or answer limit, or produces any extraneous output, your submission will be judged as a wrong answer. Note that you may need to flush the output buffer after each output. Note also that the judge for this problem is not adaptive. The judge determines before the interaction begins.
9
1
1
4
? aabb
? baa
? aa
! bbaaaaabb