Submission #139462

#TimeUsernameProblemLanguageResultExecution timeMemory
139462MeloricCombo (IOI18_combo)C++14
100 / 100
180 ms2320 KiB
#include "combo.h"
#include <bits/stdc++.h>

using namespace std;

int turn(string known, string pos){
    string a = "";
    for(char b : known){
        a+=b;
    }
    a+=pos[1];
    for(int i = 0; i< 3; i++){
        for(char b : known){
            a+= b;
        }
        a+=pos[2];
        a+=pos[i];
    }
    //cout << a << '\n';
    return press(a);
}
char beg(string pos){
    //cout << pos << "pos"<<'\n';
    if(pos.size()==1)return pos[0];
    string a = "";
    for(int i = 0; i< pos.size()/2; i++){
        a += pos[i];
    }
    //cout << a << '\n';
    int num = press(a);
    if(num > 0){
        return beg(a);
    }else{
        string b = "";
        for(int i = pos.size()/2; i < pos.size(); i++){
            b+=pos[i];
        }
        return beg(b);
    }
}
string guess_sequence(int N) {
  string but = "ABXY";
  string known = "";
  known+=beg(but);
  if(N==1)return known;
  string pos ="";
  for(auto c : but){
    if(c == known[0])continue;
    pos+=c;
  }
  //cout << pos;

  for(int i = 1; i< N-1; i++){
    int ans = turn(known, pos);
    int tmp = ans-known.size();
    if(tmp == 0)known+=pos[0];
    if(tmp == 1)known+=pos[1];
    if(tmp == 2)known+=pos[2];
  }
  //cout << known+pos[0]<<'\n';
  //cout << known+pos[1]<<'\n';
  //assert(known.size()==N-1);
  if(press(known+pos[0])==N){
    //assert(known.size()+1 == N);
    return known+pos[0];
  }
  if(press(known+pos[1])==N){
    //assert(known.size()+1 == N);
    return known+pos[1];
  }
  //assert(known.size()+1 == N);
  return known+pos[2];
}

Compilation message (stderr)

combo.cpp: In function 'char beg(std::string)':
combo.cpp:26:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i = 0; i< pos.size()/2; i++){
      |                    ~^~~~~~~~~~~~~~
combo.cpp:35:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |         for(int i = pos.size()/2; i < pos.size(); i++){
      |                                   ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...