Submission #1359638

#TimeUsernameProblemLanguageResultExecution timeMemory
1359638avahwCombo (IOI18_combo)C++20
97 / 100
5 ms484 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

std::string guess_sequence(int N) {
  std::string s = "";
  string ref = "ABXY";
  int n = N;
  // brute force first char
  for(int i = 0; i < ref.size() - 1; i++){
    int coin = press(s + ref[i]);
    if(coin == 1){ s += ref[i];
    break; }
  }
  if(s.size() == 0) s += 'Y';
  if(n == 1) return s;
  // only need to guess three other chars
  string p = "";
  for(auto e : ref) if(e != s[0]) p += e;
  for(int i = 1; i < n - 1; i++){
    string guess = 
    s + p[0] + 
    s + p[1] + p[0] + 
    s + p[1] + p[1] + 
    s + p[1] + p[2];
    int coins = press(guess);
    int gain = coins - i;
    if(gain == 0){
      s += p[2];
    }
    if(gain == 1){
      s += p[0];
    }
    if(gain == 2){
      s += p[1];
    }
  }
  for(int i = 0; i < 2; i++){
    int coin = press(s + p[i]);
    if(coin == n){
      s += p[i];
      break;
    }
  }
  if(s.size() != n) s += p[2];
  return s;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...