| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1356330 | Newtonabc | COVID tests (CEOI24_covid) | C++20 | 752 ms | 344 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,TEM;
// The probability any given student is positive
double P;
int X;
// 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.
//double UWU(double p,double n,double x){return (ceil(log2(x))*p*n)+(n/x);}
double UWU(double p,double n,double x){return pow(1.0-p,x);}
std::vector<bool> find_positive() {
std::vector<bool> answer(N,0);
for(int i=0;i<N;i++) answer[i]=0;
if(TEM==1){
for(int i=0;i<N;i++){
vector<bool> ck;
for(int j=0;j<N;j++){
if(j==i) ck.push_back(1);
else ck.push_back(0);
}
if(test_students(ck)==1) answer[i]=1;
else answer[i]=0;
}
}
else{
double n=N,p=P;
double mn=5000;
for(double x=1;x<=n;x++){
double got=UWU(p,n,x);
if(got<=(double)0.5){
X=x;
break;
}
// if(got<mn){
// mn=got;
// X=x;
// }
}
for(int i=0;i<=N-1;i+=X){
int l=i,r=min(N-1,i+X-1);
r=min(N-1,r);
vector<bool> v;
for(int i=0;i<l;i++) v.push_back(0);
for(int i=l;i<=r;i++) v.push_back(1);
for(int i=r+1;i<N;i++) v.push_back(0);
if(test_students(v)){
int lb=l,rb=r;
while(lb<rb){
int mid=(lb+rb)/2;
vector<bool> tmp=v;
for(int i=mid+1;i<=r;i++){
tmp[i]=0;
}
if(test_students(tmp)) rb=mid;
else lb=mid+1;
}
answer[lb]=1;
i=lb+1-X;
for(int i=l;i<=lb;i++) v[i]=0;
}
}
}
return answer;
}
int main() {
int T;
scanf("%d %lf %d", &N, &P, &T);
TEM=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) 메시지
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
| # | 결과 | 실행 시간 | 메모리 | 채점기 출력 |
|---|---|---|---|---|
| 결과를 불러오는 중입니다… | ||||
