Submission #1137664

#TimeUsernameProblemLanguageResultExecution timeMemory
1137664KaleemRazaSyedCOVID tests (CEOI24_covid)C++20
30.45 / 100
1024 ms428 KiB
#include<bits/stdc++.h>

using namespace std;

mt19937 rnd(std::chrono::system_clock::now().time_since_epoch().count());

int n;
double p;

map<double, int> base;

bool ask(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';
}

vector<int> fig(vector<int> a)
{
  if(a.empty()) return a;
  
  vector<bool> mask(n, false);
  vector<int> sol;
  for(int i : a) mask[i] = true;

  if(!ask(mask)) return sol;

  if(a.size() == 1) return a;


  vector<int> b;
  int c = (a.size() + base[p] - 1) / base[p];
  for(int i = 0; i < a.size(); i++)
    {
      b.push_back(a[i]);
      if(b.size() == c || i + 1 == a.size())
	{
	  vector<int> solp = fig(b);
	  for(int x : solp)
	    sol.push_back(x);
	  b.clear();
	}
    }
  return sol;
}

vector<bool> solve()
{
  vector<int> idx(n);
  iota(idx.begin(), idx.end(), 0);

  for(int i = 0; i < n; i ++)
    {
      int j = rnd() % (i + 1);
      swap(idx[i], idx[j]);
    }

  vector<bool> v(n, false);
  vector<int> sol = fig(idx);
  for(int i : sol)
    v[i] = true;
  return v;
    
}

int main()
{
  int T;
  scanf("%d %lf %d", &n, &p, &T);

  base[0.001] = 2;
  base[0.005256] = 3;
  base[0.011546] = 4; 
  base[0.028545] = 5;
  base[0.039856] = 6; 
  base[0.068648] = 7; 
  base[0.104571] = 8; 
  base[0.158765] = 9; 
  base[0.2] = 10; 
  for (int i = 0; i < T; i++) {
    vector<bool> answer = solve();
    assert(answer.size() == (size_t)n);
      
    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 (stderr)

Main.cpp: In function 'bool ask(std::vector<bool>)':
Main.cpp:24:8: 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:79:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |   scanf("%d %lf %d", &n, &p, &T);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:102:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |     scanf(" %c", &verdict);
      |     ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...