Submission #1212018

#TimeUsernameProblemLanguageResultExecution timeMemory
1212018yanbCOVID tests (CEOI24_covid)C++20
10 / 100
396 ms416 KiB
#include <bits/stdc++.h>

using namespace std;

#define int long long

int N, Block;
double P;

bool test_students(vector<bool> mask) {
    assert(mask.size() == (size_t)N);

    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';
}

bool query(int l, int r) {
    vector<bool> mask(N);
    for (int i = l; i <= r; i++) mask[i] = 1;
    return test_students(mask);
}

void dnc(vector<bool> &ans, int l, int r) {
    if (l == r) {
        ans[l] = 1;
    } else {
        int md = (l + r) / 2;
        if (query(l, md)) {
            dnc(ans, l, md);
            if (query(md + 1, r)) dnc(ans, md + 1, r);
        } else {
            dnc(ans, md + 1, r);
        }
    }
}

int get_block() {
    int l = 0, r = N;
    while (r - l > 1) {
        int md = (r + l) / 2;
        if (pow(1.0 - P, md) >= 0.5) {
            l = md;
        } else {
            r = md;
        }
    }
    return r;
}

vector<bool> find_positive() {
    vector<bool> answer(N);

    for (int l = 0; l < N; l += Block) {
        if (query(l, min(l + Block, N) - 1)) {
            for (int i = l; i < min(l + Block, N); i++) {
                if (query(i, i)) {
                    answer[i] = 1;
                }
            }
        }
    }

    return answer;
}

signed main() {
    int T;
    scanf("%d %lf %d", &N, &P, &T);

    Block = get_block();

    for (int i = 0; i < T; i++) {
        vector<bool> answer = find_positive();
        assert(answer.size() == (size_t)N);

        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 'int main()':
Main.cpp:76:13: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   76 |     scanf("%d %lf %d", &N, &P, &T);
      |            ~^          ~~
      |             |          |
      |             int*       long long int*
      |            %lld
Main.cpp:76:20: warning: format '%d' expects argument of type 'int*', but argument 4 has type 'long long int*' [-Wformat=]
   76 |     scanf("%d %lf %d", &N, &P, &T);
      |                   ~^           ~~
      |                    |           |
      |                    int*        long long int*
      |                   %lld
Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf(" %c", &answer);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...