Submission #1021430

#TimeUsernameProblemLanguageResultExecution timeMemory
1021430elipsenCombo (IOI18_combo)C++17
100 / 100
23 ms1936 KiB
#include "combo.h"
using namespace std;
#define str string
#define p press


str guess_sequence(int N) {
  str S[4] = {"A", "B", "X", "Y"};
  // Part 0: Short Case
  if (N == 1) {
    if (p("AB") == 1) {
      if (p("A") == 1) return "A";
      else return "B";
    } else {
      if (p("X") == 1) return "X";
      else return "Y";
    }
  } else {
    // Part 1: Determine the first letter (2)
    int initCombo = p("XYX") >= 1 ? 2 : 0;
    if (initCombo) initCombo += p("XAXBXY") <= 1 ? 1 : 0;
    else initCombo += p("AXAYAB") <= 1 ? 1 : 0;
    int lenCombo = 1;
    str combo = S[initCombo];
    for (int Si = initCombo; Si < 3; Si++) S[Si] = S[Si + 1];
    // Part 2: Determine letters between the first and last, if any (1 per)
    str query; int lenQuery;
    while (lenCombo < N - 1) {
      query = combo + S[0] + S[0] + 
                    combo + S[0] + S[1] + 
                    combo + S[0] + S[2] + 
                    combo + S[1];
      lenQuery = p(query);
      if (lenQuery == lenCombo + 2) combo += S[0];
      else if (lenQuery == lenCombo + 1) combo += S[1];
      else combo += S[2];
      lenCombo += 1;
    }
    // Part 3: Determine the last letter when necessary (2)
    if (lenCombo == N) return combo;
    else {
      if (p(combo + S[0]) == N) return (combo + S[0]);
      else if (p(combo + S[1]) == N) return (combo + S[1]);
      else return (combo + S[2]);
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...