Submission #248800

#TimeUsernameProblemLanguageResultExecution timeMemory
248800tqbfjotldPassword (RMI18_password)C++14
100 / 100
416 ms616 KiB
#include <bits/stdc++.h>
using namespace std;
int query(string str);

bool cmp(string s1, string s2){
    return s1.size()>s2.size();
}

priority_queue<string,vector<string>,function<bool(string,string)> > pq(cmp);

string repeat(char c, int n){
    string ret = "";
    for (int x = 0; x<n; x++){
        ret+=c;
    }
    return ret;
}

string guess(int n, int s){
    for (int x = 0; x<s; x++){
        string qu = repeat('a'+x,n);
        int t = query(qu);
        if (t!=0)pq.push(repeat('a'+x,t));
    }
    while (pq.size()>1){
        string s1 = pq.top(); pq.pop();
        string s2 = pq.top(); pq.pop();
        string nw = "";
        nw+=s2[0];
        int c1 = 0;
        int c2 = 1;
        while (nw.size()<s1.size()+s2.size()){
            string qu = nw+s1.substr(c1,s1.size());
            int t = query(qu);
            if (t==qu.size()){
                if (c2==s2.size()){
                    nw += s1.substr(c1,s1.size());
                }
                else{
                    nw += s2[c2];
                    c2++;
                }
            }
            else{
                nw.pop_back();
                c2--;
                nw += s1[c1];
                c1++;
            }
        }
        pq.push(nw);
    }
    return pq.top();
}

Compilation message (stderr)

password.cpp: In function 'std::__cxx11::string guess(int, int)':
password.cpp:35:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if (t==qu.size()){
                 ~^~~~~~~~~~~
password.cpp:36:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                 if (c2==s2.size()){
                     ~~^~~~~~~~~~~
#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...