Submission #1044471

# Submission time Handle Problem Language Result Execution time Memory
1044471 2024-08-05T10:00:57 Z c2zi6 COVID tests (CEOI24_covid) C++14
0 / 100
4296 ms 388 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef vector<bool> VB;
 
int N;
double P;
VB iskakan;

bool test_students(std::vector<bool> mask) {
    /*rep(i, N) if (mask[i] && iskakan[i]) return true;*/
    /*return false;*/

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

VB find_positive() {
    int n = N;
    if (P >= 0.2) {
        VB answer(n);
        rep(i, n) {
            VB mask(n);
            mask[i] = true;
            if (test_students(mask)) answer[i] = true;
        }
        return answer;
    } else {
        /*if (true) {*/
        /*    iskakan = VB(n);*/
        /*    string s;*/
        /*    cin >> s;*/
        /*    rep(i, n) iskakan[i] = (s[i] == '1');*/
        /*}*/
        VB answer(n);
        int cnt = (n / int(1000 * P)) * 2;
        auto binsearch = [&](int L, int R) {
            int l = L, r = R+1;
            while (l + 1 < r) {
                /*cout << l << " " << r << endl;*/
                int m = (l + r) / 2;
                VB query(n);
                replr(i, 0, m) query[i] = (true && !answer[i]);
                bool f = test_students(query);
                if (f) r = m;
                else l = m;
            }
            return r;
        };

        while (true) {
            int L = 0, R = min(n-1, L+cnt);
            int ret = binsearch(L, R);
            if (ret == R+1) {
                L = R+1, R = min(N-1, L+cnt);
            } else {
                answer[ret] = true;
                L = ret+1, R = min(n-1, L+cnt);
            }
            if (L > n-1) break;
        }
        return answer;
    }
    return VB();
}

int main() {
    int T;
    scanf("%d %lf %d", &N, &P, &T);
    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;
}




Compilation message

Main.cpp: In function 'bool test_students(std::vector<bool>)':
Main.cpp:49:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     scanf(" %c", &answer);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:104:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |     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 time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 344 KB Output is correct
2 Correct 6 ms 344 KB Output is correct
3 Correct 6 ms 344 KB Output is correct
4 Correct 6 ms 344 KB Output is correct
5 Correct 5 ms 344 KB Output is correct
6 Correct 5 ms 344 KB Output is correct
7 Correct 5 ms 388 KB Output is correct
8 Correct 5 ms 344 KB Output is correct
9 Correct 5 ms 344 KB Output is correct
10 Execution timed out 4220 ms 344 KB Time limit exceeded (wall clock)
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4296 ms 344 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -