제출 #1350492

#제출 시각아이디문제언어결과실행 시간메모리
1350492MrAndriaCOVID tests (CEOI24_covid)C++20
88.27 / 100
591 ms436 KiB
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include <bits/stdc++.h>
#define pb push_back
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)/3;
    int tm1=tm+(tr-tl)/3;
    if(b){
		if(tl==tr)return;
        rec(tl,tm);
        rec(tm+1,tm1);
        rec(tm1+1,tr);
    }else{
        for(int i=tl;i<=tr;i++){
            answer[p[i]]=0;
        }
    }
}
std::vector<bool> find_positive() {
    answer.clear();
    answer.resize(N);
    vector <int> dih;
    vector <int> vl;
    for(int i=0;i<=N-1;i++){
        answer[i]=1;
        vl.pb(i);
        p[i]=i;
    }
    for(int i=1;i<=N-1;i++){
        swap(p[i],p[rng()%(i+1)]);
    }
    for(int i=0;i<=N-1;i++){
        answer[i]=0;
    }
    int x=0;
    double prob=1;
    while(x<=N and prob*(1-P)>=0.5){
        prob*=(1-P);
        x++;
    }
    int curr=0;
    x=max(x,1);
    while(curr<N){
        int l=curr;
        int r=min(curr+x-1,N-1);
        
        vector <bool> dummy1(N,0);
        for(int i=l;i<=r;i++){
            dummy1[p[i]]=1;
        }
        bool b6=test_students(dummy1);
        if(!b6){
            curr+=x;
            continue;
        }
        while(l<r){
            vector <bool> dummy(N,0);
            int mid=(l+r)/2;
            for(int i=l;i<=mid;i++){
                dummy[p[i]]=1;
            }

            bool b=test_students(dummy);
            if(b){
                r=mid;
            }else{
                l=mid+1;
            }
        }
        if(r==-1){
            curr+=x;
        }else{
            answer[p[r]]=1;
            curr=r+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;
}

컴파일 시 표준 에러 (stderr) 메시지

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