Submission #309005

#TimeUsernameProblemLanguageResultExecution timeMemory
309005bigDuckPassword (RMI18_password)C++14
80 / 100
501 ms660 KiB


#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount



int query(string str);
/*int query(string str){
cout<<str<<"\n"<<flush; int res; cin>>res; return res;
}*/







string guess(int n, int s){
set<pair<int, char>> ord;
for(char c='a'; c<=('a'+s-1); c++){
    string st="";
    for(int i=0; i<n; i++){st.pb(c);}
    int ln=query(st);
    if(ln==0){continue;}
    ord.insert(mp(ln, c));
}

string res="";
for(int i=0; i<((ord.begin())->ft); i++){
    res.pb((ord.begin())->sc);
}
ord.erase(ord.begin());
while(!ord.empty()){
    auto it=ord.begin();

    vector<int> sum; sum.assign(n+5, 0);
    string s1=res;
    for(int i=s1.length(); i<(n); i++){
        s1.pb(it->sc);
    }
    for(int i=res.length();(i>=0 && (res.length()<n));i--){
        s1[i]=it->sc;
        int ln=query(s1);
        sum[i]=(ln-(i) );
    }
    s1.clear();
    int cnt=0;
    for(int i=res.length(); i>=0; i--){
        if(i<(res.length())){
            s1="a"+s1; s1[0]=res[i];
        }
        while(cnt<sum[i]){
            string st="a"; st[0]=(it->sc);
            s1=st+s1; cnt++;
        }

    }
    res=s1;
    ord.erase(it);
}



return res;
}


/*int main(){
cout<<guess(6, 26);




}*/


Compilation message (stderr)

password.cpp: In function 'std::string guess(int, int)':
password.cpp:50:50: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |     for(int i=res.length();(i>=0 && (res.length()<n));i--){
      |                                      ~~~~~~~~~~~~^~
password.cpp:58:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         if(i<(res.length())){
      |            ~^~~~~~~~~~~~~~~
#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...