// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
int N;
double P;
string mask;
bool qry(vi sample) {
if (sz(sample) == 0) return false;
// assert(mask.size() == (size_t)N);
for(auto& i : sample) mask[i] = '1';
cout << "Q " << mask << endl;
for(auto& i : sample) mask[i] = '0';
char answer; cin >> answer;
return answer == 'P';
}
// vi K = {2, 2, 3, 3, 4, 4, 4, 4, 4, 4};
const double eps = 1e-6;
vi get() {
vi ans;
function<void(vi, int)> dnc = [&](vi A, int d) {
if (sz(A) == 0) return;
if (sz(A) == 1) {
ans.pb(A.front());
return;
}
int M = sz(A) / 2;
vi L, R;
for(int i = 0; i < sz(A); i++) {
if (i < M) L.pb(A[i]);
else R.pb(A[i]);
}
if (!qry(L)) dnc(R, d);
else {
dnc(L, d);
if (qry(R)) dnc(R, d);
}
};
double neg = 1;
vi X; for(int i = 0; i < N; i++) {
neg *= (1 - P); X.pb(i);
if (neg < eps) {
cout << neg << " => " << i << endl;
dnc(X, 0);
X = {}; neg = 1.0;
}
}
if (qry(X)) dnc(X, 0);
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int T;
cin >> N >> P >> T;
mask = string(N, '0');
// You may perform any extra initialization here.
for (int i = 0; i < T; i++) {
vi answer = get();
// assert(answer.size() == (size_t)N);
string answer_str(N, '0');
for(auto& i : answer) answer_str[i] = '1';
cout << "A " << answer_str << endl;
char verdict; cin >> verdict;
if (verdict == 'W')
exit(0-0);
}
return 0;
}
// Breathe In, Breathe Out
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |