This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int query(string s);
string join(string x, string y)
{
int i = x.size();
int j = y.size() - 1;
string res = "";
while(i > 0)
{
while(j >= 0)
{
string q = x.substr(0, i) + y.substr(j);
if(query(q) == q.size())
{
res += y[j--];
}
else break;
}
res += x[i - 1];
i--;
}
while(j >= 0)
res += y[j--];
reverse(res.begin(), res.end());
return res;
}
string guess(int n, int s)
{
priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> pq;
for(int i = 0 ; i < s; i++)
{
string x = "";
for(int j = 0; j < n; j++)
x += char('a' + i);
int cnt = query(x);
x.clear();
while(cnt--)
x += char('a' + i);
if(cnt)pq.push({x.size(), x});
}
while(pq.size() > 1)
{
string a = pq.top().second; pq.pop();
string b = pq.top().second; pq.pop();
string r = join(a, b);
pq.push({r.size(), r});
}
return pq.top().second;
}
Compilation message (stderr)
password.cpp: In function 'std::string join(std::string, std::string)':
password.cpp:18:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
18 | if(query(q) == q.size())
| ~~~~~~~~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |