Submission #980414

#TimeUsernameProblemLanguageResultExecution timeMemory
980414kwongwengCombo (IOI18_combo)C++17
100 / 100
15 ms1756 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

string guess_sequence(int N) {
  string p = "";
  //get the first letter in 2 steps
  if (press("AB") >= 1){
    if (press("A") == 1) p += 'A';
    else p += 'B';
  }else{
    if (press("X") == 1) p += 'X';
    else p += 'Y';
  }
  if (N==1) return p;
  string pos = "";
  string T = "ABXY";
  for (int i = 0; i < 4; i++){
    if (T[i] == p[0]) continue;
    pos += T[i];
  }
  // pos will contain all characters except p[0]

  for (int i = 0; i < N-2; i++){
    string test = p+pos[1];
    for (int j = 0; j < 3; j++){
      test += p+pos[0]+pos[j];
    }
    int num = press(test);
    int len = p.size();
    if (num == len + 2) p += pos[0];
    if (num == len + 1) p += pos[1];
    if (num == len) p += pos[2];
  }
  // last letter
  for (int i = 0; i < 2; i++){
    if (press(p+pos[i])==N){
      return p+pos[i];
    }
  }
  return p+pos[2];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...