Submission #489459

#TimeUsernameProblemLanguageResultExecution timeMemory
489459QuantumK9Combo (IOI18_combo)C++17
100 / 100
31 ms604 KiB
#include "combo.h"
#include <bits/stdc++.h>

using namespace std;

string guess_sequence(int N) {

  // guess the first letter: this will take at MOST two moves
  string start = "";
  int coins = press("AB");

  if ( coins > 0 ){
    coins = press("A");
    if ( coins > 0 ){ start = "A"; }
    else{ start = "B"; }
  }
  else{
    coins = press("X");
    if ( coins > 0 ){ start = "X"; }
    else{ start = "Y"; }
  }

  if ( N == 1 ){ return start; }

  // guess the succeeding letters --> current method needs two guesses / letter
  string check[3];

  int ind = 0;
  if ( "A" != start ){ check[ind] = "A"; ind++; }
  if ( "B" != start ){ check[ind] = "B"; ind++; }
  if ( "X" != start ){ check[ind] = "X"; ind++; }
  if ( "Y" != start ){ check[ind] = "Y"; ind++; }

  for ( int i = 1; i < N-1; i++ ){

    string use = start+check[0];

    use += start+check[1]+check[0];
    use += start+check[1]+check[1];
    use += start+check[1]+check[2];


    coins = press( use );

    int diff = coins - start.length();

    if ( diff == 0 ){ start += check[2]; }
    else if ( diff == 1 ){ start += check[0]; }
    else if ( diff == 2 ){ start += check[1]; }

  }

  coins = press( start+check[0] );
 
  if ( coins == start.length()+1 ){ start += check[0]; }
  else{
      coins = press( start+check[1] );
      if ( coins == start.length()+1 ){ start += check[1]; }
      else{ start += check[2]; }
  }

  //cout << start << endl;

  return start;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:55:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   if ( coins == start.length()+1 ){ start += check[0]; }
      |        ~~~~~~^~~~~~~~~~~~~~~~~~~
combo.cpp:58:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |       if ( coins == start.length()+1 ){ start += check[1]; }
      |            ~~~~~~^~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...