| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1363943 | Aviansh | COVID tests (CEOI24_covid) | C++20 | 683 ms | 488 KiB |
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#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';
}
/// 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 calcsize(double prob){
if(prob==0.001){
return 500;
}
else if(prob==0.005256){
return 200;
}
else if(prob==0.011546){
return 100;
}
else if(prob==0.028545){
return 25;
}
else if(prob==0.039856){
return 20;
}
else if(prob==0.068648){
return 10;
}
else if(prob==0.104571){
return 10;
}
else if(prob==0.158765){
return 4;
}
else if(prob==0.2){
return 4;
}
assert(0);
}
vector<int>solve(vector<vector<int>>&posset){
int cnt = 0;
for(vector<int>v:posset){
cnt+=v.size();
}
int len = max(1,(((int)posset[0].size())/2));
vector<vector<int>>sets;
for(int x = 0;x<posset.size();x++){
vector<int>pos = posset[x];
for(int i = 0;i<pos.size();i+=len){
int j = i+len-1;
j=min(j,(int)pos.size()-1);
//check i to j as one set
vector<bool>quer(N,0);
for(int z = i;z<=j;z++){
quer[pos[z]]=1;
}
if(i+len>=pos.size()){
if(sets.size()==0){
//no prev found
vector<int>cur;
for(int z = i;z<=j;z++){
cur.push_back(pos[z]);
}
sets.push_back(cur);
continue;
}
}
if(test_students(quer)){
vector<int>cur;
for(int z = i;z<=j;z++){
cur.push_back(pos[z]);
}
sets.push_back(cur);
}
}
}
if(len==1){
//i have the answer now
vector<int>ans;
for(vector<int>v:sets){
//assert(v.size()==1);
ans.push_back(v[0]);
}
return ans;
}
else if(len<=3){
vector<int>ans;
for(vector<int>v:sets){
vector<vector<int>>temp = {v};
vector<int>cur = solve(temp);
ans.insert(ans.end(),cur.begin(),cur.end());
}
return ans;
}
vector<vector<int>>nx;
for(vector<int>v:sets){
vector<int>cur;
for(int i : v){
cur.push_back(i);
}
nx.push_back(cur);
}
if(nx.size()==0){
return {};
}
int cnt2 = 0;
for(vector<int>v:nx){
cnt2+=v.size();
}
posset.clear();
sets.clear();
return solve(nx);
}
std::vector<bool> find_positive() {
std::vector<bool> answer(N);
vector<int>curr(N);
vector<bool>temp(N,1);
if(!test_students(temp)){
return answer;
}
iota(curr.begin(),curr.end(),0);
vector<vector<int>>tem={curr};
int siz = calcsize(P);
vector<vector<int>>pass;
for(int i = 0;i<N;i+=siz){
int j = i+siz-1;
vector<int>t;
for(int z = i;z<=j;z++){
t.push_back(z);
}
pass.push_back(t);
}
vector<vector<int>>nx;
vector<bool>quer(N);
for(vector<int>v:pass){
for(int i : v){
quer[i]=1;
}
if(test_students(quer)){
nx.push_back(v);
}
for(int i : v){
quer[i]=0;
}
}
vector<int>inds = solve(nx);
for(int i : inds){
answer[i]=1;
}
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;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
