OJOnline Judge
HomeProblemsSubmissionsRankingAdmin
Sign in
← Problems/IOI18C

IOI18CCombo

Hardinteractive★ 2200interactivebinary searchconstructive
Time
2000 ms
Memory
256 MB
I/O
interactive
Tests
69 (68 hidden)
Solved
3

Combo

There is a secret sequence SSS of NNN buttons chosen from A, B, X, and Y. Determine the entire sequence by asking how much of its prefix appears inside strings that you construct. The first button of SSS is guaranteed not to appear anywhere else in SSS.

Implementation

Implement the following function:

cpp
std::string guess_sequence(int N);

The grader calls this function once and provides the length NNN of the secret sequence. Your function must return exactly SSS. Do not implement main.

Interaction

Your function may call:

cpp
int press(std::string p);

The string ppp may contain only A, B, X, and Y, and its length must not exceed 4N4N4N. The function returns the length of the longest prefix of SSS that occurs as a contiguous substring of ppp.

You may call press at most 800080008000 times. Exceeding the call limit, passing an invalid string, or returning a sequence other than SSS results in a wrong answer.

Constraints

1≤N≤20001 \le N \le 20001≤N≤2000

Si∈{A,B,X,Y}S_i \in \{\text{A}, \text{B}, \text{X}, \text{Y}\}Si​∈{A,B,X,Y}

The first character of SSS does not occur at any other position in SSS.

Example

Suppose the secret sequence is S=ABXYYS = \text{ABXYY}S=ABXYY.

Calling press("AB") returns 222, because AB, a prefix of length 222, occurs in the query and no longer prefix can fit in it. Calling press("YABX") returns 333, because ABX, a prefix of length 333, occurs contiguously in the query, while ABXY does not.

The required return value from guess_sequence(5) is "ABXYY".

Allowed languages

C++

Samples

Sample 1

Input

ABXYY

Log in to submit a solution.

Source codeType here, or drop a file onto it
Loading editor...