| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 3 초 | 1024 MB | 11 | 7 | 7 | 87.500% |
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 P=p1 p2 … pN and input Q=q1 q2 …qN, the login system’s answer is the largest L for which there exist indices 1≤ k1 < k2 < … < kL ≤ N such that qi = pki for all 1 ≤ i ≤ L. The system also tells me N, the length of my password, and S, meaning my password only uses the first S letters of the alphabet. For example, S = 4 means my password only contains a, b, c and d (but not necessarily all of them).
Please help me recover my password!
This problem is interactive. You should implement the function
string guess(int n, int s);
Your program may call the function
int query(string str);
Your program may define additional functions.
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:
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.
| 번호 | 배점 | 제한 |
|---|---|---|
| 1 | 10 | N ≤ S ≤ 26; all the letters in the password are distinct |
| 2 | 20 | 2 ≤ N ≤ 100 and 2 ≤ S ≤ 4 |
| 3 | 20 | 2 ≤ N ≤ 2,000 and 2 ≤ S ≤ 20 |
| 4 | 30 | 2 ≤ N ≤ 3,500 |
| 5 | 20 | 2 ≤ N ≤ 5,000 |
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".
C++17, C++20, C++17 (Clang), C++20 (Clang)