Submission #709226

#TimeUsernameProblemLanguageResultExecution timeMemory
709226ecxxPassword (RMI18_password)C++17
80 / 100
468 ms596 KiB
#include <bits/stdc++.h>
using namespace std;

#define ii pair<int, int>
#define startguess glen = 0
#define putguess(x) newguess[glen++] = x

int query(string str);

int q6(string str) {
    int res = query(str);
    //cout << "QUERY ON " << str << " : " << res << "\n";
    return res;
}

string st1(int n, int s) {

    // subtask one

    int exists[26] = { 0 };
    vector<ii> gthan(s, {0, 0});
    for (int i = 0; i < s; i++) gthan[i].second = i;

    char q[3] = "\0\0";


    for (int i = 0 ; i < s; i++) {
        q[0] = i + 'a';
        exists[i] = query(string(q));
    }


    for (int i = 0 ; i < s; i++) for (int j = i+1; j < s; j++) {
        if ((!exists[i]) || (!exists[j])) continue;
        q[0] = i + 'a';
        q[1] = j + 'a';
        int result = query(string(q));
        gthan[j].first += (result-1);
        gthan[i].first += (2-result);
    }  

    sort(gthan.begin(), gthan.end());

    string ans;
    for (auto q : gthan) {
        if (exists[q.second]) ans.push_back((char)(q.second + 'a'));
    }

    return ans;

}

string st3 (int n, int s) {

    int glen, guesslength;

    char buf[n+2];
    memset(buf, 0, n+2);

    char guess[n+2];
    memset(guess, 0, n+2);

    char newguess[n+2];
    memset(guess, 0, n+2);

   vector<pair<int,int> > numletter(s, {0, 0});

    for (int i = 0; i < s; i++) {
        memset(buf, i+'a', n);
        numletter[i] = {query(string(buf)), i};
    }

    sort(numletter.begin(), numletter.end());

    memset(buf, 0, n+2);
    memset(guess, 'a'+numletter[0].second, numletter[0].first);

    for (int iv = 0; iv < s-1; iv++) {

        int nltr = numletter[iv+1].second;

        //cout << guess << " " << strlen(guess) << "\n";

        memset(buf, nltr+'a', n);

        startguess;

        int nonc = numletter[iv+1].first;
        //cout << "IN TOTAL THERE ARE " << nonc << " OF " << (char)(nltr+'a') << "\n";
        for (int j = 0; j < strlen(guess); j++) {
            buf[j] = guess[j];
            int nnonc = nonc - (q6(string(buf)) - (j+1));
            //cout << "PUTTING " << nnonc << " OF " << (char)(nltr+'a') << "\n";
            for (int qqqq = 0; qqqq < nnonc; qqqq++) { 
                putguess(nltr+'a'); 
            }
            putguess(buf[j]);
            nonc -= nnonc;
        }
        for (int qqqq = 0; qqqq < nonc; qqqq++) putguess(nltr+'a');

        //cout << "IN TOTAL THERE ARE " << nonc << " OF " << (nltr+'a') << "\n\n";

        for (int z = 0; z < glen; z++) {
            guess[z] = newguess[z];
        }

    }

    return string(guess);

}

string guess (int n, int s) {
    return st3 (n, s);
}

Compilation message (stderr)

password.cpp: In function 'std::string st3(int, int)':
password.cpp:90:27: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   90 |         for (int j = 0; j < strlen(guess); j++) {
      |                         ~~^~~~~~~~~~~~~~~
password.cpp:55:15: warning: unused variable 'guesslength' [-Wunused-variable]
   55 |     int glen, guesslength;
      |               ^~~~~~~~~~~
#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...