| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1292523 | dosts | COVID tests (CEOI24_covid) | C++20 | 1102 ms | 400 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.
int s = 1;
void recalcs(int n,double p) {
double best = inf;
s = 1;
for (int j = 2;j<=n;j++){
if (p*n*log2(j)+((n+j-1)/j) < best) {
best = p*n*log2(j)+((n+j-1)/j);
s = j;
}
}
}
std::vector<bool> find_positive() {
std::vector<bool> answer(N,0);
vector<bool> test(N,0);
for (int i = 0;i<N;i+=s) {
recalcs(N-i,P);
for (int j = i;j<=i+s-1;j++) {
test[j] = 1;
}
int lst = i;
while (lst <= i+s-1 && test_students(test)) {
int l = lst;
int r = i+s-1;
while (l<=r) {
int m = (l+r) >> 1;
for (int j = lst;j<=m;j++) if (!answer[j]) test[j] = 1;
for (int j = m+1;j<=i+s-1;j++) test[j] = 0;
if (test_students(test)) r = m-1;
else l = m+1;
}
answer[l] = 1;
lst = l+1;
for (int j = i;j<=i+s-1;j++) test[j] = (j>=lst);
}
for (int j = i;j<=i+s-1;j++) {
test[j] = 0;
}
}
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... | ||||
