제출 #1044529

#제출 시각아이디문제언어결과실행 시간메모리
1044529Mher777COVID tests (CEOI24_covid)C++17
36.82 / 100
1929 ms600 KiB
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <iomanip> #include <array> #include <string> #include <algorithm> #include <cmath> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <vector> #include <stack> #include <queue> #include <deque> #include <bitset> #include <list> #include <iterator> #include <numeric> #include <complex> #include <utility> #include <random> #include <cassert> #include <fstream> using namespace std; mt19937_64 rnd(7069); typedef int itn; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef float fl; typedef long double ld; using vi = vector<int>; using vll = vector<ll>; using mii = map<int, int>; using mll = map<ll, ll>; using pii = pair<int, int>; using pll = pair<ll, ll>; #define ff first #define ss second #define pub push_back #define pob pop_back #define puf push_front #define pof pop_front #define mpr make_pair #define yes cout<<"Yes\n" #define no cout<<"No\n" #define all(x) (x).begin(), (x).end() #define USACO freopen("feast.in", "r", stdin); freopen("feast.out", "w", stdout); const int dx[8] = { -1, 0, 1, 0, -1, -1, 1, 1 }; const int dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 }; const int MAX = int(1e9 + 5); const ll MAXL = ll(1e18) + 5ll; const ll MOD = ll(1000000007); const ll MOD2 = ll(998244353); /// 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'; cout << "Q " << mask_str.c_str() << '\n'; fflush(stdout); char answer; cin >> 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> ans, harc; int n; void rec(vi v) { int m = (int)v.size(); int sq = sqrt(m); int dif = (sq - m / 2) / 8; sq = m / 2; if (P == 0.001) { sq += 0 * dif; } else if (P == 0.005256) { sq += 1 * dif; } else if (P == 0.011546) { sq += 2 * dif; } else if (P == 0.028545) { sq += 3 * dif; } else if (P == 0.039856) { sq += 4 * dif; } else if (P == 0.068648) { sq += 5 * dif; } else if (P == 0.104571) { sq += 6 * dif; } else if (P == 0.158765) { sq += 7 * dif; } else { sq = sqrt(m); } int ogt = 0, cur = 0; vi vec, used(n + 5); while (1) { int ind = v[rnd() % m]; if (used[ind]) continue; ++cur, ++ogt; vec.pub(ind); used[ind] = 1; harc[ind] = true; if (cur == sq || ogt == m) { if (test_students(harc)) { for (auto elem : vec) harc[elem] = false; if (cur == 1) ans[vec[0]] = true; else { rec(vec); } } for (auto elem : vec) harc[elem] = false; vec.clear(); cur = 0; } if (ogt == m) break; } /*for (int i = l; i <= r; ++i) { ++cur; harc[i] = true; if (cur == sq || i == r) { if (test_students(harc)) { for (int j = i - cur + 1; j <= i; ++j) harc[j] = false; if (cur == 1) ans[i] = true; else { rec(i - cur + 1, i); } } for (int j = i - cur + 1; j <= i; ++j) harc[j] = false; cur = 0; } }*/ } vector<bool> find_positive() { n = N; ans.assign(n, false); harc.assign(n, false); vi vec; for (int i = 0; i < n; ++i) { vec.pub(i); } rec(vec); return ans; } int main() { 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 << "A " << answer_str.c_str() << '\n'; fflush(stdout); char verdict; cin >> verdict; if (verdict == 'W') exit(0); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...