Submission #300176

#TimeUsernameProblemLanguageResultExecution timeMemory
300176MickyOrCombo (IOI18_combo)C++17
100 / 100
33 ms536 KiB
#include "combo.h"
#include <bits/stdc++.h>
#define fore(i, b, e) for (int i = b; i < (int)e; ++i)

using namespace std;

std::string guess_sequence(int N) {
  string pref;
  int val = press("AB");
  if (val == 0) {
    val = press("X");
    if (val == 0) pref = "Y";
    else pref = "X";
  }
  else {
    val = press("A");
    if (val == 0) pref = "B";
    else pref = "A";
  }
  if (N == 1) return pref;
  string extra = "ABXY";
  while (extra[0] != pref[0]) next_permutation(extra.begin(), extra.end());
  //assert(extra[0] == pref[0]);
  fore(i, 1, N-1) {
    string test = pref + extra.substr(1,1);
    fore(i, 1, 4) {
      test += pref;
      test += extra.substr(2,1);
      test += extra[i];
    }
    if ((int)test.size() > 4*N) break;
    //cerr << "test: " << test << endl;
    val = press(test);
    if (val == i)   pref += extra[3];
    if (val == i+1) pref += extra[1];
    if (val == i+2) pref += extra[2];
  }
  //assert((int)pref.size() == N-1);
  val = press(pref + extra.substr(1,1) + pref + extra.substr(2,1));
  if (val == N) {
    val = press(pref + extra.substr(1,1));
    if (val == N) pref += extra[1];
    else pref += extra[2];
  }
  else {
    pref += extra[3];
  }
  //cerr << "res = " << pref << endl;
  return pref;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...