#include <bits/stdc++.h>
#include <cassert>
using namespace std;
mt19937 rng;
int n;
double p;
vector<int> idx;
bool test_students(std::vector<bool> mask) {
assert(mask.size() == (size_t)n);
std::string mask_str(n, ' ');
for (int i = 0; i < n; i++)
mask_str[i] = mask[i] ? '1' : '0';
printf("Q %s\n", mask_str.c_str());
fflush(stdout);
char answer;
scanf(" %c", &answer);
return answer == 'P';
}
bool ask(vector<int>& a) {
cout << "Q ";
for (int i: a) cout << i;
cout << endl;
char c;
cin >> c;
if (c == 'P') return 1;
return 0;
}
void recorrer_arbre(int l, int r, vector<int>& ans) {
if (l == r) {
ans[idx[l]] = 1;
return;
}
vector<bool> a(n, 0);
int m = (l+r)/2;
for (int i = l; i <= m; ++i) a[idx[i]] = 1;
bool aux = test_students(a);
for (int i = l; i <= m; ++i) a[idx[i]] = 0;
if (aux) {
recorrer_arbre(l, m, ans);
for (int i = m+1; i <= r; ++i) a[idx[i]] = 1;
bool aux = test_students(a);
if (aux) recorrer_arbre(m+1, r, ans);
} else recorrer_arbre(m+1, r, ans);
}
bool ok = true;
void solve() {
idx = vector<int>(n);
for (int i = 0; i < n; ++i) idx[i] = i;
shuffle(idx.begin(), idx.end(), rng);
vector<bool> a(n, 1);
vector<int> ans(n, 0);
if (test_students(a)) recorrer_arbre(0, n-1, ans);
cout << "A ";
for (int i = 0; i < n; ++i) {
cout << ans[i];
}
cout << endl;
char c;
cin >> c;
if (c == 'W') ok = false;
}
int main() {
rng = std::mt19937(chrono::steady_clock::now().time_since_epoch().count());
int t;
cin >> n >> p >> t;
while (t--) {
solve();
if (!ok) break;
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | scanf(" %c", &answer);
| ~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |