# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1134692 | saidpon | COVID tests (CEOI24_covid) | C++17 | 0 ms | 0 KiB |
#include "bits/stdc++.h"
#define int long long
#define pb push_back
using namespace std;
int N;
double P;
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';
}
std::vector<bool> find_positive() {
std::vector<bool> answer(N), mask(N);
int k = P * N, c = N / k;
for (int i = 0; i < N; i += c) {
int L = i, R = i + c - 1;
auto check = [&](int r) {
cout << "Q ";
for (int j = 0; j < N; j++) {
if (j >= L && j <= r) cout << 1;
else cout << 0;
}
int x;
cin >> x;
return x;
};
for (int j = L; j <= R;) {
int l = j, r = R, ans = -1;
if (!check(r)) break;
while (r > l) {
int m = l + r >> 1;
if (check(m)) ans = m, r = m;
else l = m + 1;
}
answer[ans] = 1, j = ans + 1;
}
}
return answer;
}
int main() {
int T;
scanf("%d %lf %d", &N, &P, &T);
for (int i = 0; i < T; i++) {
std::vector<bool> answer = find_positive();
assert(answer.size() == (size_t)N);
std::string answer_str(N, ' ');
for (int j = 0; j < N; j++)
answer_str[j] = answer[j] ? '1' : '0';
printf("A %s\n", answer_str.c_str());
fflush(stdout);
char verdict;
scanf(" %c", &verdict);
if (verdict == 'W')
exit(0);
}
return 0;
}