Submission #1208950

#TimeUsernameProblemLanguageResultExecution timeMemory
1208950thewizardmanCombo (IOI18_combo)C++20
100 / 100
7 ms508 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

string str[3] = {"BB", "XB", "XX"};
string mt[3][3] = {
  {"Y", "Y", "Y"},
  {"XY", "BX", "BY"},
  {"BB", "XB", "XX"}
};

string guess_sequence(int n) {
  string s;
  
  if (press("AB")) {
    if (press("A")) s += "A";
    else s += "B";
  } else {
    if (press("X")) s += "X";
    else s += "Y";
  }
  
  for (auto& st: str) for (auto& c: st) if (c == s[0]) c = 'A';
  for (auto& a: mt) for (auto& st: a) for (auto& c: st) if (c == s[0]) c = 'A';

  if (n == 2) {
    if (press(s + mt[0][0][0] + s + mt[1][0][0]) == 2) {
      if (press(s + mt[0][0][0]) == 2) return s + mt[0][0][0];
      else return s + mt[1][0][0];
    }
    else return s + mt[2][0][0];
  }

  while (s.length() < n) {
    string p;
    for (auto st: str) p += s + st;
    int i = press(p) - s.length();
    if (i == 0) s += mt[0][0];
    else s += mt[i][press(s + mt[i][2]) - s.length()];
  }
  if (s.length() == n+1) s.pop_back();

  return s;
}

/*
  wlog a is first
    bb xb xx
    0 -> yb yx yy
    1 -> bx by xy
    2 -> bb xb xx
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...