Submission #1365263

#TimeUsernameProblemLanguageResultExecution timeMemory
1365263khanhphucscratchPassword (RMI18_password)C++20
30 / 100
6 ms460 KiB
#include<bits/stdc++.h>
using namespace std;
int query(string str);
string combine(string s, string t)
{
    //Combine two string
    int j = 0;
    for(int i = 0; i < s.size(); i++){
        while(j < t.size()){
            string str = s; str.insert(str.begin() + i, t[j]);
            if(query(str) == str.size()){s = str; j++; i++;}
            else break;
        }
    }
    while(j < t.size()) s += t[j++];
    return s;
}
string guess(int n, int s)
{
    vector<string> ans;
    for(int i = 0; i < s; i++){
        string cur;
        for(int j = 1; j <= n; j++) cur.push_back(i+'a');
        int num = query(cur);
        cur.clear();
        for(int j = 1; j <= num; j++) cur.push_back(i+'a');
        if(num > 0) ans.push_back(cur);
    }
    while(ans.size() > 1){
        sort(ans.begin(), ans.end(), [&](string &x, string &y){return x.size() > y.size();});
        string s = ans.back(); ans.pop_back();
        string t = ans.back(); ans.pop_back();
        //cerr<<s<<" "<<t<<endl;
        ans.push_back(combine(s, t));
    }
    return ans[0];
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...