# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1137499 | Ghulam_Junaid | COVID tests (CEOI24_covid) | C++20 | 766 ms | 408 KiB |
#include <bits/stdc++.h>
using namespace std;
int n;
double p;
bool test_students(vector<bool> mask) {
assert(mask.size() == (size_t)n);
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 range_query(int l, int r, vector<bool> &query){
if (r <= l) return 0;
r = min(r, n);
for (int i = l; i < r; i ++)
query[i] = 1;
bool res = test_students(query);
for (int i = l; i < r; i ++)
query[i] = 0;
return res;
}
vector<bool> find_positive() {
vector<bool> ans(n, 0), query(n, 0);
int l = 0;
while (l < n){
int x = ((p == 0) ? n : (1 / p));
int r = min(l + x, n);
bool val = range_query(l, r, query);
if (val == 0){
l = r;
continue;
}
int lo = l;
int hi = r;
while (hi - lo > 1){
int mid = (lo + hi) / 2;
if (range_query(l, mid, query))
hi = mid;
else
lo = mid;
}
ans[lo] = 1;
l = hi;
}
return ans;
}
int main() {
int T;
scanf("%d %lf %d", &n, &p, &T);
// You may perform any extra initialization here.
for (int i = 0; i < T; i++) {
vector<bool> answer = find_positive();
assert(answer.size() == (size_t)n);
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;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |