제출 #1364299

#제출 시각아이디문제언어결과실행 시간메모리
1364299coin_콤보 (IOI18_combo)C++20
100 / 100
6 ms668 KiB
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;

std::string guess_sequence(int N) {
  // find first one
  int n = N;
  int c1 = press("AX");
  char firstChar;
  if (c1 == 0){
    int c2 = press("B");
    if (c2 == 0){
      firstChar = 'Y';
    }
    else firstChar = 'B';
  }
  else{
    int c2 = press("A");
    if (c2 == 0){
      firstChar = 'X';
    }
    else firstChar = 'A';
  }

  vector<char> totalChar = {'A', 'B', 'X', 'Y'};
  vector<char> possibleChar;
  for (int i = 0; i < 4; i++){
    if (totalChar[i] != firstChar){
      possibleChar.push_back(totalChar[i]);
    }
  }

  string cur = "";
  cur.push_back(firstChar);
  if (n == 1){
    return cur;
  }

  for (int i = 2; i < n; i++){
    // find next char
    string ask1 = "", askTot = "", ask2 = "";
    ask1.append(cur);
    ask2.append(cur);
    ask1.push_back(possibleChar[0]);
    ask2.push_back(possibleChar[1]);
    vector<string> askQuery = {ask1, ask1, ask1};
    for (int j = 0; j < 3; j++){
      askQuery[j].push_back(possibleChar[j]);
      askTot.append(askQuery[j]);
    }
    askTot.append(ask2);
    int ci = press(askTot);
    if (ci == i-1){
      // none found => next char is 2
      cur.push_back(possibleChar[2]);
    }
    else if (ci == i){
      // ask2 matched => next char is 1
      cur.push_back(possibleChar[1]);
    }
    else{
      // ask1 matched => next char is 0
      cur.push_back(possibleChar[0]);
    }
  }

  // find last element
  string ask0 = cur + possibleChar[0], ask1 = cur + possibleChar[1];
  int cn = press(ask0+ask1);
  if (cn == n){
    int clast = press(ask0);
    if (clast == n){
      return ask0;
    }
    return ask1;
  }
  return cur + possibleChar[2];
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…