Submission #923646

#TimeUsernameProblemLanguageResultExecution timeMemory
923646LucaLucaMCombo (IOI18_combo)C++17
94 / 100
14 ms2244 KiB
#ifndef COMBO_CPP_INCLUDED
#define COMBO_CPP_INCLUDED

#include "combo.h"
#include <vector>
#include <cassert>
#include <iostream>
#include <random>

std::mt19937 rng(0);

std::string str = "";
int NNN;

std::string guess_sequence(int n) {
  NNN = n;
  std::vector<std::string> alphabet = {"A", "B", "X", "Y"};
  std::string first = "";
  for (int i = 0; i < 3; i++) {
    if (press(alphabet[i])) {
      first = alphabet[i];
      break;
    }
  }
  if (first.empty()) {
    first = alphabet.back();
  }
  int ptr = 0;
  while (alphabet[ptr] != first) {
    ptr++;
  }
  int p3[8] = {};
  p3[0] = 1;
  for (int i = 1; i < 8; i++) {
    p3[i] = 3 * p3[i - 1];
  }
  alphabet.erase(alphabet.begin() + ptr);
  str += first;
  for (int i = 1; i + 1 < n; i++) {
    std::string ask = str + alphabet[0];
    for (int i = 0; i < 3; i++) {
      ask += str + alphabet[1] + alphabet[i];
    }
    int ret = press(ask);
    if (ret == (int) str.size()) {
      str += alphabet[2];
    } else if (ret == 1 + (int) str.size()) {
      str += alphabet[0];
    } else {
      str += alphabet[1];
    }
  }
  for (int i = 0; i < 2; i++) {
    if (press(str + alphabet[i]) == 1 + (int) str.size()) {
      str += alphabet[i];
    }
  }
  if ((int) str.size() < n) {
    str += alphabet[2];
  }
  return str;
}


#endif // COMBO_CPP_INCLUDED
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...