제출 #1222895

#제출 시각아이디문제언어결과실행 시간메모리
1222895AriadnaCOVID tests (CEOI24_covid)C++20
49.63 / 100
857 ms424 KiB
#include <bits/stdc++.h>
#include <cassert>
using namespace std;

int n;
double p;
vector<int> idx;

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


bool ask(vector<int>& a) {
    cout << "Q ";
    for (int i: a) cout << i;
    cout << endl;
    char c;
    cin >> c;
    if (c == 'P') return 1;
    return 0;
}

void recorrer_arbre(int l, int r, vector<int>& ans) {
    if (l == r) {
        ans[idx[l]] = 1;
        return;
    }
    vector<bool> a(n, 0);
    int m = (l+r)/2;
    for (int i = l; i <= m; ++i) a[idx[i]] = 1;
    bool aux = test_students(a);
    for (int i = l; i <= m; ++i) a[idx[i]] = 0;
    if (aux) {
        recorrer_arbre(l, m, ans);
        for (int i = m+1; i <= r; ++i) a[idx[i]] = 1;
        bool aux = test_students(a);
        if (aux) recorrer_arbre(m+1, r, ans);
    } else recorrer_arbre(m+1, r, ans);
    
}
bool ok = true;
void solve() {
    int aux = 1/p;
    vector<int> ans(n, 0);
    idx = vector<int>(n);
    for (int i = 0; i < n; ++i) idx[i] = i;
    for (int i = 1; (i-1)*aux-1 <= n-1; ++i) {
        int l = (i-1)*aux, r = min(n-1, i*aux-1);
        vector<bool> a(n, 0);
        for (int j = l; j <= r; ++j) a[j] = 1;
        if (test_students(a)) recorrer_arbre(l, r, ans);
    }
    cout << "A ";
    for (int i = 0; i < n; ++i) {
        cout << ans[i];
    }
    cout << endl;
    char c;
    cin >> c;
    if (c == 'W') ok = false;
}

int main() {
    int t;
    cin >> n >> p >> t;
    while (t--) {
        solve();
        if (!ok) break;
    }

    return 0;
}

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

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