답안 #1114863

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114863 2024-11-19T17:20:14 Z PagodePaiva COVID tests (CEOI24_covid) C++17
10 / 100
5339 ms 504 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){
  int con = 0;
  for(int i = 0;i < v.size();i++){
    if(v[i]) con++;
  }
  if(con == 1){
    set <int> res;
    for(int i = 0;i < v.size();i++){
      if(v[i]) res.insert(i);
    }
    return res;
  }
  vector <bool> a1(N), a2(N);
  int d = 0;
  for(int i = 0;i < v.size();i++){
    int p = con/2;
    a1[i] = false;
    a2[i] = false;
    if(v[i]){
      if(d < p){
        a1[i] = true;
      }
      else{
        a2[i] = true;
      }
      d++;
    }
  }
  set <int> ans;
  if(test_students(a1)){
    set <int> aux = find(a1);
    for(auto x : aux){
      ans.insert(x);
    }
  }
  if(test_students(a2)){
    set <int> aux2 = find(a2);
    for(auto x : aux2){
      ans.insert(x);
    }
  }
  return ans;
}

std::vector<bool> find_positive() {
    std::vector<bool> answer(N);
    int n = N;
    vector <bool> v;    
    int tam = 1;
    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){
      v.clear();
      for(int j = 0;j < n;j++){
        v.push_back(false);
      }
      for(int j = i;j < min(i+tam, 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.
    int p = P;
    tam = 1;
    while(P > 0.5){
      P *= p;
      tam++;
      if(tam == N) break;
    }
    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 'std::set<int> find(std::vector<bool>&)':
Main.cpp:30:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |   for(int i = 0;i < v.size();i++){
      |                 ~~^~~~~~~~~~
Main.cpp:35:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(int i = 0;i < v.size();i++){
      |                   ~~^~~~~~~~~~
Main.cpp:42:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int i = 0;i < v.size();i++){
      |                 ~~^~~~~~~~~~
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:103:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |     scanf("%d %lf %d", &N, &P, &T);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:125:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  125 |         scanf(" %c", &verdict);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 336 KB Output is correct
2 Correct 20 ms 504 KB Output is correct
3 Correct 20 ms 336 KB Output is correct
4 Correct 22 ms 336 KB Output is correct
5 Correct 22 ms 336 KB Output is correct
6 Correct 19 ms 336 KB Output is correct
7 Correct 22 ms 336 KB Output is correct
8 Correct 22 ms 336 KB Output is correct
9 Correct 25 ms 336 KB Output is correct
10 Correct 21 ms 336 KB Output is correct
11 Correct 23 ms 336 KB Output is correct
12 Correct 26 ms 336 KB Output is correct
13 Correct 20 ms 336 KB Output is correct
14 Correct 18 ms 336 KB Output is correct
15 Correct 18 ms 336 KB Output is correct
16 Correct 23 ms 336 KB Output is correct
17 Correct 18 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5339 ms 336 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -