# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
646262 | Matteo_Verz | Password (RMI18_password) | C++17 | 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>
#ifdef BLAT
#include "debug/debug.hpp"
#include "password.h"
#else
#define debug(x...)
#endif
using namespace std;
string mergeStrings(string &a, string &b) {
string mergedSoFar, queryString;
while (a.size() || b.size()) {
if (!a.size()) {
mergedSoFar += b;
return mergedSoFar;
}
queryString = mergedSoFar + a[0] + b;
int len = query(queryString);
if (len == queryString.size()) {
mergedSoFar.push_back(a[0]);
a.erase(0, 1);
} else {
mergedSoFar.push_back(b[0]);
b.erase(0, 1);
}
}
return mergedSoFar;
}
string guess(int n, int s) {
string ask;
vector <string> vs;
for (char ch = 'a'; ch - 'a' < s; ch++) {
ask.clear();
for (int i = 0; i < n; i++)
ask += ch;
int len = query(ask);
ask = "";
for (int i = 0; i < len; i++)
ask += ch;
vs.push_back(ask);
}
while (vs.size() > 1) {
string a = vs.back();
vs.pop_back();
string b = vs.back();
vs.pop_back();
string c = mergeStrings(a, b);
vs.push_back(c);
}
return vs[0];
}