#include "bits/stdc++.h"
using namespace std;
int query(string str);
#define sz(a) (int)a.size()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
string guess(int n, int s) {
vector<pair<int, char>> v;
for(int f = 0; f < s; ++f) {
char c = char('a' + f);
string paiu = string(n, c);
int x = query(paiu);
if(x > 0) {
v.push_back({x, c});
}
}
assert(v.size() > 0);
sort(v.begin(), v.end());
string ans = string(v[0].first, v[0].second);
v.erase(v.begin());
assert(sz(ans) > 0);
if(!sz(v)) return ans;
for(auto noo: v) {
char c = noo.second;
int cnt = noo.first;
string ff = ans;
string bruh = "";
for(int i = 0; i <= sz(ff); ++i) {
int lol = 0, l = 1, r = cnt;
string rem = bruh;
while(l <= r) {
int mid = l + r >> 1;
bruh = rem;
for(int j = 0; j < mid; ++j) bruh += c;
for(int k = i; k < sz(ff); ++k) {
bruh += ff[k];
}
if(query(bruh) == sz(bruh)) {
lol = mid;
l = mid + 1;
} else r = mid - 1;
}
cnt -= lol;
bruh = rem;
for(int j = 0; j < lol; ++j) bruh += c;
if(i < sz(ff)) bruh += ff[i];
}
ans = bruh;
}
return ans;
}
Compilation message
password.cpp: In function 'std::string guess(int, int)':
password.cpp:36:29: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
36 | int mid = l + r >> 1;
| ~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Guessed the password with 76 queries. |
2 |
Correct |
2 ms |
208 KB |
Guessed the password with 187 queries. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Guessed the password with 52 queries. |
2 |
Correct |
2 ms |
208 KB |
Guessed the password with 120 queries. |
3 |
Correct |
0 ms |
208 KB |
Guessed the password with 14 queries. |
4 |
Correct |
4 ms |
208 KB |
Guessed the password with 347 queries. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
149 ms |
444 KB |
Guessed the password with 12712 queries. |
2 |
Correct |
302 ms |
320 KB |
Guessed the password with 34055 queries. |
3 |
Correct |
246 ms |
416 KB |
Guessed the password with 22667 queries. |
4 |
Incorrect |
554 ms |
544 KB |
Could not guess the password with 50000 queries. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Guessed the password with 76 queries. |
2 |
Correct |
2 ms |
208 KB |
Guessed the password with 187 queries. |
3 |
Correct |
1 ms |
208 KB |
Guessed the password with 52 queries. |
4 |
Correct |
2 ms |
208 KB |
Guessed the password with 120 queries. |
5 |
Correct |
0 ms |
208 KB |
Guessed the password with 14 queries. |
6 |
Correct |
4 ms |
208 KB |
Guessed the password with 347 queries. |
7 |
Correct |
149 ms |
444 KB |
Guessed the password with 12712 queries. |
8 |
Correct |
302 ms |
320 KB |
Guessed the password with 34055 queries. |
9 |
Correct |
246 ms |
416 KB |
Guessed the password with 22667 queries. |
10 |
Incorrect |
554 ms |
544 KB |
Could not guess the password with 50000 queries. |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Guessed the password with 76 queries. |
2 |
Correct |
2 ms |
208 KB |
Guessed the password with 187 queries. |
3 |
Correct |
1 ms |
208 KB |
Guessed the password with 52 queries. |
4 |
Correct |
2 ms |
208 KB |
Guessed the password with 120 queries. |
5 |
Correct |
0 ms |
208 KB |
Guessed the password with 14 queries. |
6 |
Correct |
4 ms |
208 KB |
Guessed the password with 347 queries. |
7 |
Correct |
149 ms |
444 KB |
Guessed the password with 12712 queries. |
8 |
Correct |
302 ms |
320 KB |
Guessed the password with 34055 queries. |
9 |
Correct |
246 ms |
416 KB |
Guessed the password with 22667 queries. |
10 |
Incorrect |
554 ms |
544 KB |
Could not guess the password with 50000 queries. |
11 |
Halted |
0 ms |
0 KB |
- |