Submission #923653

#TimeUsernameProblemLanguageResultExecution timeMemory
923653LucaLucaM콤보 (IOI18_combo)C++17
97 / 100
20 ms1996 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();
  }
  if (n == 1) {
    return first;
  }
  int ptr = 0;
  while (alphabet[ptr] != first) {
    ptr++;
  }
  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];
    }
    assert((int) ask.size() <= 4 * n);
    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...