Submission #709209

# Submission time Handle Problem Language Result Execution time Memory
709209 2023-03-13T08:20:21 Z ecxx Password (RMI18_password) C++17
50 / 100
188 ms 208 KB
#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);

    int numletter[26] = {0};

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

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

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

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

        memset(buf, i+1+'a', n);

        startguess;

        int nonc = numletter[i+1];
        //cout << "IN TOTAL THERE ARE " << nonc << " OF " << (char)(i+1+'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)(i+1+'a') << "\n";
            for (int qqqq = 0; qqqq < nnonc; qqqq++) { 
                putguess(i+1+'a'); 
            }
            putguess(buf[j]);
            nonc -= nnonc;
        }
        for (int qqqq = 0; qqqq < nonc; qqqq++) putguess(i+1+'a');

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

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

    }

    return string(guess);

}

string guess (int n, int s) {
    if (s <= 20) return st3 (n, s);
  	return st1 (n, s);
}

Compilation message

password.cpp: In function 'std::string st3(int, int)':
password.cpp:86:27: warning: comparison of integer expressions of different signedness: 'int' and 'size_t' {aka 'long unsigned int'} [-Wsign-compare]
   86 |         for (int j = 0; j < strlen(guess); j++) {
      |                         ~~^~~~~~~~~~~~~~~
password.cpp:55:15: warning: unused variable 'guesslength' [-Wunused-variable]
   55 |     int glen, guesslength;
      |               ^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Guessed the password with 121 queries.
2 Correct 4 ms 208 KB Guessed the password with 277 queries.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Guessed the password with 27 queries.
2 Correct 2 ms 208 KB Guessed the password with 106 queries.
3 Correct 1 ms 208 KB Guessed the password with 26 queries.
4 Correct 1 ms 208 KB Guessed the password with 133 queries.
# Verdict Execution time Memory Grader output
1 Correct 42 ms 208 KB Guessed the password with 3818 queries.
2 Correct 79 ms 208 KB Guessed the password with 9474 queries.
3 Correct 145 ms 208 KB Guessed the password with 12785 queries.
4 Correct 188 ms 208 KB Guessed the password with 18895 queries.
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Guessed the password with 121 queries.
2 Correct 4 ms 208 KB Guessed the password with 277 queries.
3 Correct 1 ms 208 KB Guessed the password with 27 queries.
4 Correct 2 ms 208 KB Guessed the password with 106 queries.
5 Correct 1 ms 208 KB Guessed the password with 26 queries.
6 Correct 1 ms 208 KB Guessed the password with 133 queries.
7 Correct 42 ms 208 KB Guessed the password with 3818 queries.
8 Correct 79 ms 208 KB Guessed the password with 9474 queries.
9 Correct 145 ms 208 KB Guessed the password with 12785 queries.
10 Correct 188 ms 208 KB Guessed the password with 18895 queries.
11 Incorrect 3 ms 208 KB Returned early from guess() after 352 queries.
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 208 KB Guessed the password with 121 queries.
2 Correct 4 ms 208 KB Guessed the password with 277 queries.
3 Correct 1 ms 208 KB Guessed the password with 27 queries.
4 Correct 2 ms 208 KB Guessed the password with 106 queries.
5 Correct 1 ms 208 KB Guessed the password with 26 queries.
6 Correct 1 ms 208 KB Guessed the password with 133 queries.
7 Correct 42 ms 208 KB Guessed the password with 3818 queries.
8 Correct 79 ms 208 KB Guessed the password with 9474 queries.
9 Correct 145 ms 208 KB Guessed the password with 12785 queries.
10 Correct 188 ms 208 KB Guessed the password with 18895 queries.
11 Incorrect 3 ms 208 KB Returned early from guess() after 352 queries.
12 Halted 0 ms 0 KB -