Submission #709262

#TimeUsernameProblemLanguageResultExecution timeMemory
709262HalogenPassword (RMI18_password)C++14
0 / 100
4 ms556 KiB
#include <bits/stdc++.h> using namespace std; int query(string q); string obtainstr(string s, int m, char i) { if (m <= 0) return i + s; if (m >= s.length()) return s + i; return s.substr(0, m) + i + s.substr(m); } string guess(int n, int s) { string ans = ""; int amt[s + 5]; for (int i = 0; i < s; i++) { amt[i] = query(string(n, 'a' + i)); } for (int i = 0; i < s; i++) if (amt[i]) { ans = string(amt[i], 'a' + i); break; } char cur = ans[0] - 'a' + 1; while (cur < s) { int l = 0, r = ans.length(); if (amt[cur] <= 0) {++cur; continue;} while(l <= r) { int m = l+r >> 1; int res = query(obtainstr(ans, m, 'a' + cur)); if (res >= ans.length() + 1) l = m + 1; else r = m - 1; } --amt[cur]; ans = ans.substr(0, r) + char('a' + cur) + ans.substr(r); } return ans; }

Compilation message (stderr)

password.cpp: In function 'std::string obtainstr(std::string, int, char)':
password.cpp:9:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |     if (m >= s.length()) return s + i;
      |         ~~^~~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:29:17: warning: array subscript has type 'char' [-Wchar-subscripts]
   29 |         if (amt[cur] <= 0) {++cur; continue;}
      |                 ^~~
password.cpp:32:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |             int m = l+r >> 1;
      |                     ~^~
password.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |             if (res >= ans.length() + 1) l = m + 1;
      |                 ~~~~^~~~~~~~~~~~~~~~~~~
password.cpp:39:15: warning: array subscript has type 'char' [-Wchar-subscripts]
   39 |         --amt[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...