# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
773335 | aykhn | Password (RMI18_password) | C++14 | 0 ms | 0 KiB |
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>
// author: aykhn
using namespace std;
typedef long long ll;
int cnt[30];
priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>> pq;
int query(string str);
void MERGE(string &a, string &b)
{
int prev = query(b);
for (int j = 0; j < b.length(); j++)
{
string tmp = b;
b.ins(b.begin() + j, a[i]);
int x = query(b);
if (x <= prev) b = tmp;
else i++;
}
}
string guess(int n, int s)
{
string tmp = "";
for (int i = 0; i < n; i++)
{
tmp.pb('a');
}
int prev = 0;
for (int i = 0; i < s; i++)
{
cnt[i] = query(temp);
pq.push(cnt[i], temp.substr(0, cnt[i]));
for (int j = 0; j < n; j++) tmp[j]++;
}
while (pq.size() > 1)
{
string a = pq.top().se;
pq.pop();
string b = pq.top().se;
pq.pop();
MERGE(a, b);
pq.push(mpr(b.length(), b));
}
return pq.top();
}