제출 #858097

#제출 시각아이디문제언어결과실행 시간메모리
858097alexddPassword (RMI18_password)C++17
80 / 100
476 ms2088 KiB
#include<bits/stdc++.h>
using namespace std;
int query(string str);
string tostr(int x, int cnt)
{
    string cv = "";
    for(int i=0;i<cnt;i++)
        cv.push_back((char)('a'+x));
    return cv;
}
pair<int,int> v[30];
string guess(int n, int s)
{
    string aux;
    for(int i=0;i<s;i++)
    {
        aux = tostr(i, n);
        v[i]={query(aux), i};
    }
    sort(v,v+s);
    string rez="";
    for(int i=0;i<s;i++)
    {
        int cnt = v[i].first;
        int x = v[i].second;
        if(cnt==0)
            continue;
        if((int)rez.size()==0)
        {
            rez = tostr(x, cnt);
            continue;
        }
        if((int)rez.size()==n)
            break;
        string newrez="";

        int nr = query(rez + tostr(x, n - (int)rez.size())) - (int)rez.size();
        newrez = newrez + tostr(x, nr);
        int suff = nr;
        for(int j=(int)rez.size()-1;j>=0;j--)
        {
            if((int)newrez.size()==n)
                break;
            int nr = (query(rez.substr(0,j) + tostr(x, n - (int)rez.size())) - j) - suff;
            newrez = newrez + rez[j] + tostr(x, nr);
            suff = nr + suff;
        }
        reverse(newrez.begin(),newrez.end());
        rez = newrez;
    }
    return rez;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...