#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int>vi;
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
typedef string str;
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)
void ckmin(int &x, int y){x=min(x,y);}
//------------------------------------
const int alp=26;
void upd(str &s, int i, char c){
s.insert(s.begin()+i,c);
}
bool check(str s, int idx, char c){
str ss; ss+=c;
FOR(i,idx,sz(s)) ss+=s[i];
return query(ss)==sz(ss);
}
str guess(int N, int S){
vi nb(alp);
for(char c='a'; c<='z'; c++){
str s;
FOR(i,0,N) s+=c;
//cout << query(s) << endl;
nb[c-'a']=query(s);
}
int idx=0;
FOR(i,0,alp) if(nb[i]>nb[idx]) idx=i;
str cur;
FOR(i,0,nb[idx]) cur+=char(idx+'a');
FOR(i,0,alp) if(i!=idx){
char c=i+'a';
while(nb[i]--){
int l=0,r=sz(cur),ind=-1;
while(l<=r){
int m=(l+r)/2;
if(check(cur,m,c)){
ind=m;
r=m-1;
}
else l=m+1;
}
upd(cur,ind,c);
//cout << cur << endl;
}
}
return cur;
}
Compilation message
password.cpp: In function 'bool check(str, int, char)':
password.cpp:30:12: error: 'query' was not declared in this scope
30 | return query(ss)==sz(ss);
| ^~~~~
password.cpp: In function 'str guess(int, int)':
password.cpp:39:19: error: 'query' was not declared in this scope
39 | nb[c-'a']=query(s);
| ^~~~~