Submission #1271001

#TimeUsernameProblemLanguageResultExecution timeMemory
1271001OmarAlimammadzadeCombo (IOI18_combo)C++20
100 / 100
8 ms532 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

string guess_sequence(int N) {
  vector<string> buttons = {"A", "B", "X", "Y"};
  string s;

  int x = press("AB");
  if (!x) {
    x = press("X");
    if (!x) {
      s = "Y";
    } else {
      s = "X";
    }
  } else {
    x = press("A");
    if (!x) {
      s = "B";
    } else {
      s = "A";
    }
  }
  
  for (int i = 0; i < 4; i++) {
    if (buttons[i] == s) {
      buttons.erase(buttons.begin() + i);
      break;
    }
  }

  if (N == 1) {
    goto skip;
  }

  for (int i = 1; i < N - 1; i++) {
    string p;
    p += s + buttons[0];
    for (int j = 0; j < 3; j++) {
      p += s + buttons[1] + buttons[j];
    }
    int x = press(p);
    if (x == i + 1) {
      s += buttons[0];
    } else if (x == i + 2) {
      s += buttons[1];
    } else {
      s += buttons[2];
    }
  }

  if (press(s + buttons[0]) == N) {
    s += buttons[0];
  } else if (press(s + buttons[1]) == N) {
    s += buttons[1];
  } else {
    s += buttons[2];
  }

skip:
  return s;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...