#include <bits/stdc++.h>
using namespace std ;
const int MAX = 1e5 + 10 ;
int arr[MAX] , freq[27] , before[27][27] , letters[MAX] ;
int n , c ;
string ans = "" ;
int Query(string s)
{
cout<<s<<endl ;
int x ;
cin>>x ;
if(x == n)
exit(0) ;
return x ;
}
bool Check_Before(int a , int b)
{
string s = ans ;
s.push_back((char)(a+'a')) ;
for(int i = 0 ; i < freq[b] ; ++i)
s.push_back((char)(b+'a')) ;
return (Query(s) == s.size()) ;
}
bool cmp(int &a , int &b)
{
return before[a][b] ;
}
int main()
{
//ios_base::sync_with_stdio(0) ;
//cin.tie(0) ;
cin>>n>>c ;
for(int i = 0 ; i < c ; ++i)
freq[i] = Query(string(n , (char)('a'+i))) ;
for(int i = 0 ; i < c ; ++i)
{
for(int j = i+1 ; j < c ; ++j)
{
before[i][j] = Check_Before(i , j) ;
if(!before[i][j])
before[j][i] = 1 ;
}
}
for(int i = 0 ; i < c ; ++i)
letters[i] = i ;
sort(letters , letters + c , cmp) ;
for(int i = 0 ; i < n ; ++i)
{
int x = letters[0] ;
freq[x]-- ;
ans.push_back((char)(x+'a')) ;
int l = 1 , r = c-1 ;
int idx = 0 ;
if(freq[x] == 0)
idx = c-1 ;
else
{
while(l <= r)
{
int mid = (l + r) >> 1 ;
if(!Check_Before(letters[0] , letters[mid]))
idx = mid , l = mid+1 ;
else
r = mid-1 ;
}
}
for(int i = 0 ; i < idx ; ++i)
letters[i] = letters[i+1] ;
letters[idx] = x ;
}
Query(ans) ;
return 0 ;
}
Compilation message
password.cpp: In function 'bool Check_Before(int, int)':
password.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
return (Query(s) == s.size()) ;
~~~~~~~~~^~~~~~~~~~~
/tmp/ccj1ENPo.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cc3SGUEi.o:password.cpp:(.text.startup+0xc0): first defined here
/tmp/ccj1ENPo.o: In function `main':
grader.cpp:(.text.startup+0x5f): undefined reference to `guess[abi:cxx11](int, int)'
collect2: error: ld returned 1 exit status