# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1237209 | The_Samurai | COVID tests (CEOI24_covid) | C++20 | 869 ms | 408 KiB |
#include "bits/stdc++.h"
using namespace std;
/// You may use:
// The number of students
int n;
// The probability any given student is positive
double P;
// This function performs a test on a subset of samples.
// Its argument is a vector of Booleans of length N,
// where the i-th element is true if the i-th sample should be added to the mix.
// It returns true if (and only if) at least one of the samples in the mix is positive.
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';
}
int f(int l, int r) {
int best = -1, start = l;
while (l <= r) {
int mid = (l + r) >> 1;
vector<bool> shit(n);
for (int i = start; i <= mid; i++) shit[i] = true;
if (test_students(shit)) {
best = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
return best;
}
std::vector<bool> find_positive() {
int exp = n * P, best = 1e9;
for (int ln = 1; ln <= n; ln++) {
int now = (n + ln - 1) / ln;
now += log2(ln) * max(now, exp);
best = min(best, now);
}
vector<bool> ans(n);
for (int ln = 1; ln <= n; ln++) {
int now = (n + ln - 1) / ln;
now += log2(ln) * max(now, exp);
if (now != best) continue;
for (int i = 0; i * ln < n; i++) {
int l = i * ln, r = min(n - 1, (i + 1) * ln - 1);
while (l <= r) {
int best = f(l, r);
if (best == -1) break;
ans[best] = true;
l = best + 1;
}
}
break;
}
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++) {
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;
}
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... |