Submission #1137499

#TimeUsernameProblemLanguageResultExecution timeMemory
1137499Ghulam_JunaidCOVID tests (CEOI24_covid)C++20
89.83 / 100
766 ms408 KiB
#include <bits/stdc++.h>
using namespace std;

int n;
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 range_query(int l, int r, vector<bool> &query){
    if (r <= l) return 0;

    r = min(r, n);
    for (int i = l; i < r; i ++)
        query[i] = 1;
    bool res = test_students(query);
    for (int i = l; i < r; i ++)
        query[i] = 0;
    return res;
}

vector<bool> find_positive() {
    vector<bool> ans(n, 0), query(n, 0);
    int l = 0;
    while (l < n){
        int x = ((p == 0) ? n : (1 / p));
        int r = min(l + x, n);
        bool val = range_query(l, r, query);
        
        if (val == 0){
            l = r;
            continue;
        }

        int lo = l;
        int hi = r;
        while (hi - lo > 1){
            int mid = (lo + hi) / 2;
            if (range_query(l, mid, query))
                hi = mid;
            else
                lo = mid;
        }
        ans[lo] = 1;
        l = hi;
    }
    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++) {
        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 'bool test_students(std::vector<bool>)':
Main.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |     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...