#include <bits/stdc++.h>
using namespace std;
int query(string q);
string uni(char c, int l){
string r;
for(int i = 0; i<l; i++){
r.push_back(c);
}
return r;
}
string merge(string a, string b){
if(a.size()<b.size()){
return merge(b, a);
}
int p = 0;
int nb_ins= 0;
while(p<=a.size()&& nb_ins<b.size()){
string r2 = a;
r2.insert(r2.begin()+ p, b[nb_ins]);
if(query(r2) == r2.size()){
swap(a, r2);
nb_ins++;
}
p++;
}
return a;
}
vector<int> oc;
string dpr(int lt, int rt){
if(lt == rt){
return uni(lt+'a', oc[lt]);
}
else{
int mid = (lt+rt)/2;
return merge(dpr(lt, mid), dpr(mid+1, rt));
}
}
string guess(int n, int s){
pii best;
string r;
oc.resize(s);
for(int i = 0; i<s; i++){
string a;
int l =0;
char c= 'a'+i;
oc[i] = query(uni(c, n));
//cout<<c<<" "<<oc[i]<<endl;
if(oc[i]>best.first){
best.first = oc[i];
best.second = i;
}
}
r = dpr(0, s-1);
return r;
}
Compilation message
password.cpp: In function 'std::string merge(std::string, std::string)':
password.cpp:22:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | while(p<=a.size()&& nb_ins<b.size()){
| ~^~~~~~~~~~
password.cpp:22:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | while(p<=a.size()&& nb_ins<b.size()){
| ~~~~~~^~~~~~~~~
password.cpp:25:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | if(query(r2) == r2.size()){
| ~~~~~~~~~~^~~~~~~~~~~~
password.cpp: In function 'std::string guess(int, int)':
password.cpp:49:3: error: 'pii' was not declared in this scope
49 | pii best;
| ^~~
password.cpp:60:14: error: 'best' was not declared in this scope
60 | if(oc[i]>best.first){
| ^~~~
password.cpp:54:9: warning: unused variable 'l' [-Wunused-variable]
54 | int l =0;
| ^