Submission #1142575

#TimeUsernameProblemLanguageResultExecution timeMemory
1142575qwerty13579Combo (IOI18_combo)C++20
0 / 100
0 ms408 KiB
#include "bits/stdc++.h"
#include "combo.h"

using namespace std;

std::string guess_sequence(int n) {
  string pb = "ABXY";
  string possibilities = "";
  string p = "";
  string s = "";

  if (press("AB") > 0){ // if AB is 1
    if (press("A") == 1) p += 'A'; // if A is 1 add to s A
    else p += 'B'; // else add to s B
  } else if (press("X") == 1) p += 'X'; // if X is 1 add to s X
  else p+='Y'; // else add Y

  s=p;

  for (int i=0;i<pb.size();++i){
    if (pb[i]==s[0]) continue;
    possibilities+=pb[i];
  }

  int last_ans = 1;
  while(true)
  {
    if (p.size()==n-1){
      break;
    }
    string toAdd = ""; // str to add to not modify p yet

    toAdd+=possibilities[0]; // add first character
    toAdd+=p; // add prefix
    toAdd+=possibilities[1]; // add second character

    // to second character add all the possibilities
    for(int i=0;i<possibilities.size();++i){
      toAdd+=possibilities[i];
      if (i<possibilities.size()-1){
        toAdd+=p;
        toAdd+=possibilities[1];
      }
    }
    // ask
    // if ((p + toAdd).size() > 4*n) break;
    int ans = press(p + toAdd);
    if (ans-last_ans==1){
      p+=possibilities[0];
    } else if (ans-last_ans > 1){
      p+=possibilities[1];
    } else {
      p+=possibilities[2];
    }

    last_ans = ans;
  }

  if(press(p + possibilities[0]) + 1 - last_ans == 1) p+=possibilities[0];
  else if(press(p + possibilities[1]) + 1 - last_ans == 1) p+=possibilities[1];
  else p+=possibilities[2];

  s=p;
  
  return s;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...