| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1346046 | MrAndria | COVID tests (CEOI24_covid) | C++20 | 91 ms | 452 KiB |
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N;
double P;
int p[1005];
std::vector<bool> answer;
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';
}
void rec(vector <int> vec){
if(vec.size()==0)return;
vector <bool> dummy(N,0);
for(int i=0;i<vec.size();i++){
dummy[vec[i]]=1;
}
bool b=test_students(dummy);
if(b){
if(vec.size()==1)return;
while(true){
vector <int> v[3];
for(int i=0;i<vec.size();i++){
v[rng()%3].pb(vec[i]);
}
if(v[0].size()==vec.size() or v[1].size()==vec.size() or v[2].size()==vec.size())continue;
rec(v[0]);
rec(v[1]);
rec(v[2]);
break;
}
}else{
for(int i=0;i<vec.size();i++){
answer[vec[i]]=0;
}
}
}
std::vector<bool> find_positive() {
answer.clear();
answer.resize(N);
vector <int> dih;
vector <int> vl;
for(int i=0;i<=N-1;i++){
answer[i]=0;
vl.pb(i);
p[i]=i;
}
for(int i=1;i<=N-1;i++){
swap(p[i],p[rng()%i]);
}
if(P<0.02){
int x=P*N;
x=(N/max(1,x));
int curr=0;
while(curr<N){
int l=curr;
int r=(curr+x,N-1);
int ans=-1;
while(l<=r){
vector <bool> dummy(N,0);
int mid=(l+r)/2;
for(int i=l;i<=mid;i++){
dummy[p[i]]=1;
}
bool b=test_students(dummy);
if(b){
ans=mid;
r=mid-1;
}else{
l=mid+1;
}
}
if(ans==-1){
curr+=x;
}else{
answer[p[ans]]=1;
curr=ans+1;
}
}
}else{
rec(vl);
}
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... | ||||
