| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1285076 | weebyeah | COVID tests (CEOI24_covid) | C++20 | 981 ms | 432 KiB |
#include <bits/stdc++.h>
using namespace std;
#define Umazing ios::sync_with_stdio(false); cin.tie(nullptr);
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
/// 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(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.
vector<bool> find_positive()
{
vector<int> sta(N);
double ap;
if (P >= 0.13)
ap = 0.40;
else if (P >= 0.10)
ap = 0.45;
else
ap = 0.50;
while (true)
{
int cc = 0;
for (int i = 0; i < N; i++)
{
if (sta[i] == 0)
cc++;
}
if (cc == 0)
break;
int g;
if (P <= 0.0)
g = cc;
else if (P >= 1.0)
g = 1;
else
{
double dd = log(1.0 - P);
if (dd == 0.0)
g = 1;
else
{
int cand = floor(log(ap) / dd);
if (cand < 1)
cand = 1;
if (cand > cc)
cand = cc;
g = cand;
}
}
if (g < 1)
g = 1;
if (g > cc)
g = cc;
vector<int> gr;
for (int i = 0; i < N && gr.size() < g; i++)
{
if (sta[i] == 0)
gr.push_back(i);
}
vector<bool> m(N, false);
for (int idx: gr)
{
m[idx] = true;
}
bool ps = test_students(m);
if (!ps)
{
for (int x: gr)
{
sta[x] = 1;
}
continue;
}
while (!gr.empty())
{
vector<int> gg = gr;
while (gg.size() > 1)
{
int s = gg.size();
int pow2 = 1;
while ((pow2 << 1) <= s)
{
pow2 <<= 1;
}
int k = s - pow2;
if (k == 0)
k = s / 2;
vector<int> l(gg.begin(), gg.begin() + k);
vector<int> r(gg.begin() + k, gg.end());
vector<bool> ml(N, false);
for (int x: l)
{
ml[x] = true;
}
bool lp = test_students(ml);
if (lp)
gg.swap(l);
else
{
for (int x: l)
{
sta[x] = 1;
}
gg.swap(r);
}
}
int pos = gg[0];
sta[pos] = 2;
vector<int> grn;
for (int x: gr)
{
if (x != pos)
grn.push_back(x);
}
if (grn.empty())
break;
vector<bool> mrem(N, false);
for (int x: grn)
{
mrem[x] = true;
}
bool mm = test_students(mrem);
if (!mm)
{
for (int x: grn)
{
sta[x] = 1;
}
gr.clear();
break;
}
else
gr.swap(grn);
}
}
vector<bool> res(N, false);
for (int i = 0; i < N; i++)
{
res[i] = (sta[i] == 2);
}
return res;
}
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);
}
}
컴파일 시 표준 에러 (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... | ||||
