답안 #1114883

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114883 2024-11-19T17:42:52 Z PagodePaiva COVID tests (CEOI24_covid) C++17
10 / 100
6037 ms 642904 KB
#include<bits/stdc++.h>

using namespace std;

vector <int> idx;

int n, t;

bool query(string &s){
  cout << "Q " << s << '\n';
  cout << flush;
  char c;
  cin >> c;
  if(c == 'P')
    return true;
  return false;
}

string solve(string &s){
  string s1, s2;
  int con = 0;
  for(int i = 0;i < s.size();i++){
    s1.push_back('0');
    s2.push_back('0');
    if(s[i] == '1') con++;
  }
  if(con == 1) return s;
  int d = 0, p = con/2;
  for(int i = 0;i < s.size();i++){
    if(s[idx[i]] == '1'){
      if(d < p){
        s1[idx[i]] = '1';
      }
      else{
        s2[idx[i]] = '1';
      }
      d++;
    }
  }
  string ans;
  for(int i = 0;i < n;i++)
    ans.push_back('0');
  if(query(s1)){
    string res = solve(s1);
    for(int i = 0;i < n;i++){
      if(res[i] == '1') ans[i] = '1';
    }
  }
  if(query(s2)){
    string res = solve(s2);
    for(int i = 0;i < n;i++){
      if(res[i] == '1') ans[i] = '1';
    }
  }
  return ans;
}

int main(){
  srand(time(0));
  double p;
  cin >> n >> p >> t;
  int tam = 1;
  while(t--){
    string s;
    for(int i = 0;i < n;i++){
      s.push_back('1');
    }
    for(int i = 0;i < n;i++){
      idx.push_back(i);
    }
    random_shuffle(idx.begin(), idx.end());
    if(!query(s)){
      cout << "A ";
      for(int i = 0;i < n;i++){
        cout << 0;
      }
      cout << '\n';
      cout << flush;
      char c;
      cin >> c;
      continue;
    }
    string res = solve(s);
    idx.clear();
    cout << "A " << res << '\n';
    cout << flush;
    char c;
    cin >> c;
    if(c == 'W')
      exit(0);
  }
}

Compilation message

Main.cpp: In function 'std::string solve(std::string&)':
Main.cpp:22:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |   for(int i = 0;i < s.size();i++){
      |                 ~~^~~~~~~~~~
Main.cpp:29:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(int i = 0;i < s.size();i++){
      |                 ~~^~~~~~~~~~
Main.cpp: In function 'int main()':
Main.cpp:62:7: warning: unused variable 'tam' [-Wunused-variable]
   62 |   int tam = 1;
      |       ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 336 KB Output is correct
2 Correct 45 ms 504 KB Output is correct
3 Correct 49 ms 336 KB Output is correct
4 Correct 53 ms 336 KB Output is correct
5 Correct 54 ms 336 KB Output is correct
6 Correct 49 ms 336 KB Output is correct
7 Correct 41 ms 336 KB Output is correct
8 Correct 36 ms 336 KB Output is correct
9 Correct 45 ms 336 KB Output is correct
10 Correct 25 ms 336 KB Output is correct
11 Correct 37 ms 336 KB Output is correct
12 Correct 40 ms 336 KB Output is correct
13 Correct 38 ms 336 KB Output is correct
14 Correct 43 ms 336 KB Output is correct
15 Correct 39 ms 336 KB Output is correct
16 Correct 53 ms 504 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 6037 ms 642904 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -