Submission #709186

#TimeUsernameProblemLanguageResultExecution timeMemory
709186HalogenPassword (RMI18_password)C++14
50 / 100
385 ms484 KiB
#include <bits/stdc++.h> using namespace std; int query(string q); string guess(int n, int s) { string ans = ""; set<char> remaining; int amt[s + 5]; int cnt = 0; for (char i = 0; i < s; i++) { string g(n, i + 'a'); amt[i] = query(g); cnt += amt[i]; if (amt[i] > 0) remaining.insert(i); if (cnt == n) break; if (amt[i] == n) return g; } for (int k = 0; k < n; k++) { char cur = *remaining.begin(); for (char i : remaining) { if (i == cur) continue; string g(amt[cur], 'a' + cur); g += ('a' + i); g += ans; int res = query(g); if (res != g.size()) continue; cur = i; } ans = string(1, 'a' + cur) + ans; amt[cur]--; if (amt[cur] == 0) remaining.erase(cur); if (remaining.size() == 1) { cur = *remaining.begin(); string g(amt[cur], 'a' + cur); return g + ans; } } return ans; }

Compilation message (stderr)

password.cpp: In function 'std::string guess(int, int)':
password.cpp:15:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   15 |         amt[i] = query(g);
      |             ^
password.cpp:16:20: warning: array subscript has type 'char' [-Wchar-subscripts]
   16 |         cnt += amt[i];
      |                    ^
password.cpp:18:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   18 |         if (amt[i] > 0) remaining.insert(i);
      |                 ^
password.cpp:20:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   20 |         if (amt[i] == n) return g;
      |                 ^
password.cpp:27:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   27 |             string g(amt[cur], 'a' + cur);
      |                          ^~~
password.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |             if (res != g.size()) continue;
      |                 ~~~~^~~~~~~~~~~
password.cpp:37:13: warning: array subscript has type 'char' [-Wchar-subscripts]
   37 |         amt[cur]--;
      |             ^~~
password.cpp:39:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |         if (amt[cur] == 0) remaining.erase(cur);
      |                 ^~~
password.cpp:42:26: warning: array subscript has type 'char' [-Wchar-subscripts]
   42 |             string g(amt[cur], 'a' + cur);
      |                          ^~~
#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...