답안 #1114887

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114887 2024-11-19T17:47:41 Z PagodePaiva COVID tests (CEOI24_covid) C++17
컴파일 오류
0 ms 0 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 s1, s2;
string ans;
string res;
string aa;

string solve(string &s){
  s1.clear();
  s2.clear();
  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++;
    }
  }
  aa = s;
  ans.clear()
  for(int i = 0;i < n;i++)
    ans.push_back('0');
  s = s1;
  if(query(s)){
    string res = solve(s);
    for(int i = 0;i < n;i++){
      if(res[i] == '1') ans[i] = '1';
    }
  }
  s = s2;
  if(query(s)){
    string res = solve(s);
    for(int i = 0;i < n;i++){
      if(res[i] == '1') ans[i] = '1';
    }
  }
  s = aa;
  return ans;
}

int main(){
  ios::sync_with_stdio(false); cin.tie(0);
  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:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |   for(int i = 0;i < s.size();i++){
      |                 ~~^~~~~~~~~~
Main.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int i = 0;i < s.size();i++){
      |                 ~~^~~~~~~~~~
Main.cpp:47:14: error: expected ';' before 'for'
   47 |   ans.clear()
      |              ^
      |              ;
   48 |   for(int i = 0;i < n;i++)
      |   ~~~         
Main.cpp:48:17: error: 'i' was not declared in this scope
   48 |   for(int i = 0;i < n;i++)
      |                 ^
Main.cpp: In function 'int main()':
Main.cpp:73:7: warning: unused variable 'tam' [-Wunused-variable]
   73 |   int tam = 1;
      |       ^~~