# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476229 | iulia13 | 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>
using namespace std;
const int N = 5005;
string ans, prov;
int cnt[N], nn, ss;
string p, password;/*
int query(string q) {
int len = q.size();
// validation
// while possible, advance one character in q and find its next
// occurrence in password
int i = 0, j = 0, plen = password.size();
while (i < plen && j < len) {
while ((i < plen) && (password[i] != q[j])) {
i++;
}
if (i < plen) {
i++;
j++;
}
}
return j;
}*/
string guess(int n, int s)
{
char a;
int q = 0;
for (int i = 0; i < s; i++)
{
a = 'a' + i;
p = ans;
for (int j = q; j < n; j++)
p += a;
for (int h = q; h >= 0; h--)
{
cnt[h] = query(p) - h;
if (h)
p[h - 1] = a;
}
int nq = 0;
prov = "";
for (int j = 0; j <= q; j++)
{
int x = cnt[j] - cnt[j + 1];
while(x--)
{
prov += a;
nq++;
}
if (j != q)
{
prov += ans[j];
nq++;
}
}
q = nq;
ans = prov;
}
return ans;
}/*
int main()
{
freopen("x.in", "r", stdin);
freopen("x.out", "w", stdout);
int nn, ss;
cin >> nn >> ss;
cin >> password;
cout << guess(nn, ss);
return 0;
}*/