Submission #1346003

#TimeUsernameProblemLanguageResultExecution timeMemory
1346003MrAndriaCOVID tests (CEOI24_covid)C++20
39.85 / 100
783 ms448 KiB
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int N;
double P;
int p[1005];
std::vector<bool> answer;
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';
}
void rec(int tl,int tr){
    if(tl>tr)return;
    vector <bool> dummy(N,0);
    for(int i=tl;i<=tr;i++){
        dummy[p[i]]=1;
    }
    bool b=test_students(dummy);
    int tm=tl+(tr-tl)/4;
    int tm1=tm+(tr-tl)/4;
    int tm2=tm1+(tr-tl)/4;
    if(b){
		if(tl==tr)return;
        rec(tl,tm);
        rec(tm+1,tm1);
        rec(tm1+1,tm2);
        rec(tm2+1,tr);
    }else{
        for(int i=tl;i<=tr;i++){
            answer[p[i]]=0;
        }
    }
}
std::vector<bool> find_positive() {
    answer.clear();
    answer.resize(N);
    for(int i=0;i<=N-1;i++){
        answer[i]=1;
        p[i]=i;
    }
    for(int i=1;i<=N-1;i++){
        swap(p[i],p[rng()%i]);
    }
    rec(0,N-1);
    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:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf(" %c", &answer);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...