Submission #709246

#TimeUsernameProblemLanguageResultExecution timeMemory
709246hmm789Password (RMI18_password)C++14
80 / 100
1335 ms556 KiB
#include <bits/stdc++.h> using namespace std; int query(string s); string guess(int n, int s) { int cnt = 1; string ans = ""; pair<int, int> occ[s]; for(int i = 0; i < s; i++) { string s; for(int j = 0; j < n; j++) s += (char)('a'+i); occ[i].first = query(s); occ[i].second = i; //~ cout << "a " << i << " " << l-1 << endl; } sort(occ, occ+s); for(int i = 0; i < occ[0].first; i++) ans += (char)('a'+occ[0].second); for(int i = 1; i < s; i++) { //~ cout << "s" << i << ": " << ans << endl; int tmpcnt[ans.size()+1], sm = 0; memset(tmpcnt, 0, sizeof(tmpcnt)); for(int j = ans.size(); j >= 0; j--) { string tmp = ""; for(int k = 0; k < j; k++) tmp += ans[k]; for(int k = 0; k < n-j; k++) tmp += (char)('a'+occ[i].second); int tmp2 = query(tmp); tmpcnt[j] = tmp2-sm-j; sm += tmpcnt[j]; } string tmp = ""; for(int j = 0; j < ans.size(); j++) tmp += ans[j]; //~ cout << "s" << i << ": " << tmp << endl; ans = ""; for(int j = 0; j < tmpcnt[0]; j++) ans += (char)('a'+occ[i].second); for(int j = 1; j <= tmp.size(); j++) { //~ cout << "s" << i << "(" << j << "): " << ans << endl; ans += tmp[j-1]; for(int k = 0; k < tmpcnt[j]; k++) ans += (char)('a'+occ[i].second); } //~ cout << "s" << i << ": " << ans << endl; } return ans; }

Compilation message (stderr)

password.cpp: In function 'std::string guess(int, int)':
password.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int j = 0; j < ans.size(); j++) tmp += ans[j];
      |                  ~~^~~~~~~~~~~~
password.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int j = 1; j <= tmp.size(); j++) {
      |                  ~~^~~~~~~~~~~~~
password.cpp:6:6: warning: unused variable 'cnt' [-Wunused-variable]
    6 |  int cnt = 1;
      |      ^~~
#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...