Submission #1114871

# Submission time Handle Problem Language Result Execution time Memory
1114871 2024-11-19T17:31:02 Z PagodePaiva COVID tests (CEOI24_covid) C++17
0 / 100
1 ms 512 KB
#include <cassert>
#include <cstdio>
#include <string>
#include <vector>
#include<bits/stdc++.h>

using namespace std;

int N;
double P;
int tam;

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

set <int> find(vector <bool> &v){
  set <int> ans;
  vector <bool> aux;
  for(int i = 0;i < N;i++){
    aux.push_back(false);
  }
  for(int i = 0;i < N;i++){
    if(v[i]){
      aux[i] = true;
      if(test_students(aux)) ans.insert(i);
      aux[i] = false;
    }
  }
  return ans;
}

std::vector<bool> find_positive() {
    std::vector<bool> answer(N);
    int n = N;
    vector <bool> v;
    vector <int> idx;
    for(int i = 0;i < n;i++){
      idx.push_back(i);
      answer[i] = false;
    }
    random_shuffle(idx.begin(), idx.end());
    for(int i = 0;i < n;i += tam+1){
      v.clear();
      for(int j = 0;j < n;j++){
        v.push_back(false);
      }
      for(int j = i;j < min(i+tam+1, n);j++){
        v[idx[j]] = true;
      }
      if(!test_students(v)) continue;
      set <int> aux = find(v);
      for(auto x : aux){
        answer[x] = true;
      }
    }
    return answer;
}

int main() {
    srand(69);
    int T;
    scanf("%d %lf %d", &N, &P, &T);
    // You may perform any extra initialization here.
    P = 1-P;
    double p = P;
    tam = 1;
    while(P > 0.5){
      P *= p;
      tam++;
      if(tam == N) break;
    }
    cout << tam << '\n';
    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:24:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |     scanf(" %c", &answer);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:74:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:97:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   97 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 512 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 336 KB Execution killed with signal 13
2 Halted 0 ms 0 KB -