#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.
map<vector<bool>, bool> mp;
bool test_students(std::vector<bool> mask) {
if (mp.count(mask)) return mp[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';
cout << mask_str << endl;
char answer;
cin >> answer;
return mp[mask] = (answer == 'P');
}
int f(int l, int r) {
int best = -1, start = l;
while (l <= r) {
int mid = (l + r) >> 1;
vector<bool> shit(n);
for (int i = start; i <= mid; i++) shit[i] = true;
if (test_students(shit)) {
best = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
return best;
}
std::vector<bool> find_positive() {
mp.clear();
int exp = n * P, best = 1e9;
for (int ln = 1; ln <= n; ln++) {
int now = (n + ln - 1) / ln;
now += (log2(ln) + 1) * exp;
best = min(best, now);
}
vector<bool> ans(n);
for (int ln = 1; ln <= n; ln++) {
int now = (n + ln - 1) / ln;
now += (log2(ln) + 1) * exp;
if (now != best) continue;
for (int i = 0; i * ln < n; i++) {
int l = i * ln, r = min(n - 1, (i + 1) * ln - 1);
while (l <= r) {
vector<bool> shit(n);
for (int j = l; j <= r; j++) shit[j] = true;
if (!test_students(shit)) break;
int best = f(l, r);
if (best == -1) break;
ans[best] = true;
l = best + 1;
if (l > r) break;
}
}
break;
}
return ans;
}
int main() {
cin.tie(0)->sync_with_stdio(false);
int T;
cin >> 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';
cout << answer_str << endl;
char verdict;
cin >> verdict;
if (verdict == 'W')
exit(0);
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |