| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1292570 | dosts | COVID tests (CEOI24_covid) | C++20 | 792 ms | 436 KiB |
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2")
//#define int long long
#define pii pair<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define sp << " " <<
#define all(x) x.begin(),x.end()
#define big(x) ((int)(x.size()))
using namespace std;
const int MOD = 1e9+7, LIM = 1e6+1, inf = 2e9;
/// 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';
}
/// You should implement:
// This function will be called once for each test instance.
// It should use test_students to determine which samples are positive.
// It must return a vector of Booleans of length N,
// where the i-th element is true if and only if the i-th sample is positive.
std::vector<bool> find_positive() {
std::vector<bool> answer(N,0);
vi unknown;
for (int j = 0;j<N;j++) unknown.push_back(j);
vector<bool> test(N,0);
while (big(unknown)) {
test.assign(N,0);
vi newunknown;
int s = 1;
double best = inf;
for (int j = 2;j<=big(unknown);j++) {
if (P*big(unknown)*__lg(2*j-1)+((big(unknown)+j-1)/j) < best) {
best = P*big(unknown)*__lg(2*j-1)+((big(unknown)+j-1)/j);
s = j;
}
}
for (int i = 0;i<big(unknown);i+=s) {
int R = min(big(unknown)-1,i+s-1);
for (int j = i;j<=R;j++) test[unknown[j]] = 1;
if (!test_students(test)) continue;
int l = i;
int r = R;
while (l<r) {
int m = (l+r) >> 1;
for (int j = i;j<=m;j++) if (!answer[unknown[j]]) test[unknown[j]] = 1;
for (int j = m+1;j<=R;j++) test[unknown[j]] = 0;
if (test_students(test)) r = m;
else l = m+1;
}
answer[unknown[l]] = 1;
for (int j = l+1;j<=R;j++) newunknown.push_back(unknown[j]);
for (int j = i;j<=R;j++) test[unknown[j]] = 0;
}
unknown = newunknown;
}
return answer;
}
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... | ||||
