제출 #1346048

#제출 시각아이디문제언어결과실행 시간메모리
1346048MrAndriaCOVID tests (CEOI24_covid)C++20
0 / 100
95 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]=0;
        vl.pb(i);
        p[i]=i;
    }
    for(int i=1;i<=N-1;i++){
        swap(p[i],p[rng()%i]);
    }
    if(P<0.02){
        int x=P*N;
        x=(N/max(1,x));
        int curr=0;
        while(curr<N){
            int l=curr;
            int r=(curr+x,N-1);
            int ans=-1;
            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){
                    ans=mid;
                    r=mid-1;
                }else{
                    l=mid+1;
                }
            }
            if(ans==-1){
                curr+=x;
            }else{
                answer[p[ans]]=1;
                curr=ans+1;
            }
        }
    }else{
        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;
}

컴파일 시 표준 에러 (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:98:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:114:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  114 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...