#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int query(string str);
string ans;
void mergesort(ll l, ll r){
if(l >= r)
return;
ll m = (l+r)/2;
mergesort(l, m);
mergesort(m+1, r);
ll it1 = l, it2 = m+1;
string newans;
while(it2 <= r){
while(1){
string tmp;
if(!newans.empty())
tmp += newans;
tmp += ans[it2];
tmp += ans.substr(it1, m-it1+1);
if(it1 == m+1 || query(tmp) == tmp.size()){
newans.pb(ans[it2]);
break;
}
newans.pb(ans[it1]);
++it1;
}
++it2;
}
while(it1 <= m){
newans.pb(ans[it1]);
++it1;
}
for(ll i = l; i <= r; ++i){
ans[i] = newans[i-l];
}
}
int check(char c, int cnt){
if(cnt == 0)
return 1;
string tmp;
for(ll i = 0; i < cnt; ++i)
tmp.pb(c);
return (query(tmp) == cnt);
}
string guess(int n, int s){
ll curtot = 0;
for(ll i = 0; i < s; ++i){
ll l = 0, r = n-curtot;
while(l < r){
ll m = (l+r+1)/2;
if(check('a'+i, m))
l = m;
else
r = m-1;
}
curtot += l;
while(l--)
ans.pb('a'+i);
}
mergesort(0, n-1);
return ans;
}
Compilation message
password.cpp: In function 'void mergesort(ll, ll)':
password.cpp:31:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it1 == m+1 || query(tmp) == tmp.size()){
~~~~~~~~~~~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
248 KB |
Guessed the password with 90 queries. |
2 |
Correct |
6 ms |
376 KB |
Guessed the password with 155 queries. |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Guessed the password with 165 queries. |
2 |
Incorrect |
7 ms |
376 KB |
Returned early from guess() after 232 queries. |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
376 KB |
Returned early from guess() after 5311 queries. |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
248 KB |
Guessed the password with 90 queries. |
2 |
Correct |
6 ms |
376 KB |
Guessed the password with 155 queries. |
3 |
Correct |
7 ms |
376 KB |
Guessed the password with 165 queries. |
4 |
Incorrect |
7 ms |
376 KB |
Returned early from guess() after 232 queries. |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
248 KB |
Guessed the password with 90 queries. |
2 |
Correct |
6 ms |
376 KB |
Guessed the password with 155 queries. |
3 |
Correct |
7 ms |
376 KB |
Guessed the password with 165 queries. |
4 |
Incorrect |
7 ms |
376 KB |
Returned early from guess() after 232 queries. |
5 |
Halted |
0 ms |
0 KB |
- |