Submission #1356291

#TimeUsernameProblemLanguageResultExecution timeMemory
1356291NewtonabcCOVID tests (CEOI24_covid)C++20
10 / 100
1248 ms412 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-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=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);
            while(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;
                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;
}

Compilation message (stderr)

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