This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int query(string str);
string a, q;
vector<string> v;
string merge(string s1, string s2){
int p1 = 0, p2 = 0;
while(p1 < s1.size() && p2 < s2.size()){
q = s1;
q.insert(q.begin() + p1, s2[p2]);
if(query(q) == q.size()){
s1 = q;
p2++;
}
p1++;
}
for(int i = p2; i < s2.size(); i++){
s1 += s2[i];
}
return s1;
}
bool comp(string& a, string& b){
return a.size() > b.size();
}
string guess(int n, int s){
for(char c = 'a'; c <= 'a' + s - 1; c++){
a = "";
for(int i = 1; i <= n; i++){
a += c;
}
int cnt = query(a);
if(cnt == 0) continue;
a = "";
for(int i = 1; i <= cnt; i++){
a += c;
}
v.push_back(a);
}
sort(v.begin(), v.end(), comp);
while(v.size() > 1){
a = merge(v[v.size() - 1], v[v.size() - 2]);
v.pop_back();
v.pop_back();
v.push_back(a);
sort(v.begin(), v.end(), comp);
}
return v[0];
}
Compilation message (stderr)
password.cpp: In function 'std::string merge(std::string, std::string)':
password.cpp:12:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | while(p1 < s1.size() && p2 < s2.size()){
| ~~~^~~~~~~~~~~
password.cpp:12:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | while(p1 < s1.size() && p2 < s2.size()){
| ~~~^~~~~~~~~~~
password.cpp:15:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
15 | if(query(q) == q.size()){
| ~~~~~~~~~^~~~~~~~~~~
password.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = p2; i < s2.size(); i++){
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |