I forgot my password again! I am sitting at my computer punching in wrong passwords. All I remember is that my password contains only lowercase letters. Luckily, the login system responds with more than just "wrong password". It also tells me the length of the longest prefix of my input that occurs as a (not necessarily contiguous) subsequence in the password. Formally, for a password and input , the login system’s answer is the largest for which there exist indices such that for all . The system also tells me , the length of my password, and , meaning my password only uses the first letters of the alphabet. For example, means my password only contains a
, b
, c
and d
(but not necessarily all of them).
Please help me recover my password!
Implementation details
This problem is interactive. You should implement the function:
string guess(int n, int s);
- Arguments: and as described above.
- Return value: the correct password.
Your program may call the function:
int query(string str);
- Argument: a string of to letters from among the first letters of the alphabet.
- Return value: an integer between and the length of , representing the login system’s answer to your query.
- To avoid compiler errors, you should declare this function using the exact text above, anywhere in the global scope before calling it.
- You may call this function at most times for each test case.
Your program may define additional functions.
Sample grader
A sample_grader.cpp
is provided for you to test your code locally. The sample grader reads the input from the file password.in
in the format:
- line 1:
N S
- line 2:
password
You can compile the grader together with your solution. Then you can run the resulting binary to test your guessing strategy against the given input.
Subtasks
Subtask | Percentage of points | Input constraints |
---|---|---|
1 | 10% | ; all the letters in the password are distinct |
2 | 20% | and |
3 | 20% | and |
4 | 30% | |
5 | 20% |
Example
Let the password be aab
. The grader calls guess(3, 2)
. The call log may be:
Call | Return value |
---|---|
guess("ab") | 2 |
guess("abb") | 2 |
guess("bab") | 1 |
guess("aab") | 3 |
At this point, guess(3, 2)
should return "aab"
.