Submission #1281220

#TimeUsernameProblemLanguageResultExecution timeMemory
1281220ZeroCoolCOVID tests (CEOI24_covid)C++20
100 / 100
779 ms400 KiB
#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.

#define ar array

map<ar<int,2>,int> mp;

bool qry(int l,int r){
    // if(mp.count({l, r}))return mp[{l, r}];
    vector<bool> v(n, 0);
    for(int i = l;i <= r;i++)v[i] = 1;
    return test_students(v);
}

std::vector<bool> find_positive() {
    // mp.clear();
    int i = 0;

    int k = 1;
    double pp = 1 - P;
    double x = 1;
    double LIM = 0.5;
    if(P == 0.104571)LIM = 0.45;
    for(int i = 0;i <= n;i++){
        if(x < LIM)break;
        k = i;
        x *= pp;
    }
    k = max(k, 1);
    // cout<<k<<'\n';
    vector<bool> ans(n, 0);
    while(i < n){
        int j = min(n - 1, i + k - 1);
        if(qry(i, j)){
            int lo = i - 1, hi = j;
            while(hi - lo > 1){
                int mid = (lo + hi) / 2;
                if(qry(i, mid))hi = mid;
                else lo = mid;
            }
            ans[hi] = 1;
            i = hi + 1;
        }else i += k;
    }
    return ans;


    //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;
}

Compilation message (stderr)

Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     scanf(" %c", &answer);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:88:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |     scanf("%d %lf %d", &n, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:104:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...