Submission #709209

#TimeUsernameProblemLanguageResultExecution timeMemory
709209ecxxPassword (RMI18_password)C++17
50 / 100
188 ms208 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); 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 (stderr)

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 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...