#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "C:\GCC\debug.h"
#else
#define debug(...) void(42)
#endif
string hidden;
int nn;
int ss;
int cnt = 0;
/*
int query(string str) {
++cnt;
assert((int) str.size() <= nn);
for (auto c : str) {
assert(c - 'a' <= ss);
}
// cout << str << endl;
int ptr = 0;
for (int i = 0; i < (int) str.length(); i++) {
while (ptr < (int) hidden.length() && hidden[ptr] != str[i]) {
++ptr;
}
if (ptr == (int) hidden.length()) {
return i;
}
ptr++;
}
}
*/
int query(string str);
string guess(int n, int s) {
nn = n;
ss = s;
string endChars;
vector<int> freq(s);
for (int i = 0; i < s; i++) {
string str;
for (int it = 0; it < n; it++) {
str += (i + 'a');
}
freq[i] = query(str);
if (freq[i] == n) {
return str;
}
}
for (int pos = n - 1; pos >= 0; pos--) {
for (int i = 0; i < s; i++) {
if (freq[i] > 0) {
string build;
for (int it = 0; it < freq[i]; it++) {
build += (i + 'a');
}
bool work = true;
if ((int) build.length() < pos + 1) {
for (int j = 0; j < s; j++) {
string tmp;
tmp += build;
tmp += (j + 'a');
tmp += endChars;
if (query(tmp) == (int) tmp.length()) {
work = false;
break;
}
}
}
if (work) {
freq[i] -= 1;
endChars.insert(endChars.begin(), i + 'a');
break;
}
}
}
}
return endChars;
}
/*
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int times = 100;
while (times--) {
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
hidden.clear();
int n = rng() % 100 + 1;
for (int i = 0; i < n; i++) {
hidden += ((rng() % 4) + 'a');
}
string str = guess(n, 4);
debug(str, hidden);
debug(cnt);
assert(str == hidden);
cnt = 0;
}
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Guessed the password with 427 queries. |
2 |
Correct |
13 ms |
208 KB |
Guessed the password with 1209 queries. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
208 KB |
Guessed the password with 135 queries. |
2 |
Runtime error |
3 ms |
208 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
412 ms |
588 KB |
Execution killed with signal 13 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Guessed the password with 427 queries. |
2 |
Correct |
13 ms |
208 KB |
Guessed the password with 1209 queries. |
3 |
Correct |
2 ms |
208 KB |
Guessed the password with 135 queries. |
4 |
Runtime error |
3 ms |
208 KB |
Execution killed with signal 13 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
208 KB |
Guessed the password with 427 queries. |
2 |
Correct |
13 ms |
208 KB |
Guessed the password with 1209 queries. |
3 |
Correct |
2 ms |
208 KB |
Guessed the password with 135 queries. |
4 |
Runtime error |
3 ms |
208 KB |
Execution killed with signal 13 |
5 |
Halted |
0 ms |
0 KB |
- |