제출 #1237226

#제출 시각아이디문제언어결과실행 시간메모리
1237226The_SamuraiCOVID tests (CEOI24_covid)C++20
82.74 / 100
6692 ms648 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.
map<vector<bool>, bool> mp;

bool test_students(std::vector<bool> mask) {
    if (mp.count(mask)) return mp[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 mp[mask] = (answer == 'P');
}

int f(int l, int r) {
    int best = -1, start = l;
    while (l <= r) {
        int mid = (l + r) >> 1;
        vector<bool> shit(n);
        for (int i = start; i <= mid; i++) shit[i] = true;
        if (test_students(shit)) {
            best = mid;
            r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    return best;
}

std::vector<bool> find_positive() {
    mp.clear();
    int exp = n * P, best = 1e9;
    for (int ln = 1; ln <= n; ln++) {
        int now = (n + ln - 1) / ln;
        now += (log2(ln) + 1) * exp;
        best = min(best, now);
    }
    vector<bool> ans(n);
    for (int ln = 1; ln <= n; ln++) {
        int now = (n + ln - 1) / ln;
        now += (log2(ln) + 1) * exp;
        if (now != best) continue;
        for (int i = 0; i * ln < n; i++) {
            int l = i * ln, r = min(n - 1, (i + 1) * ln - 1);
            while (l <= r) {
                vector<bool> shit(n);
                for (int j = l; j <= r; j++) shit[j] = true;
                if (!test_students(shit)) break;
                int best = f(l, r);
                if (best == -1) break;
                ans[best] = true;
                l = best + 1;
                if (l > r) break;
            }
        }
        break;
    }
    return ans;
}

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: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:83:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |     scanf("%d %lf %d", &n, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:99:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...