Submission #1111437

#TimeUsernameProblemLanguageResultExecution timeMemory
1111437SalihSahinCombo (IOI18_combo)C++14
5 / 100
1 ms508 KiB
#include <bits/stdc++.h>
#define pb push_back
#include "combo.h"
using namespace std;

string guess_sequence(int N) {
  string p = "A", ans = "";
  int c = press(p);
  if(c) ans += 'A';
  p = "B";
  c = press(p);
  if(c && !ans.size()) ans += 'B';
  p = "X";
  c = press(p);
  if(c && !ans.size()) ans += 'X';
  p = "X";
  if(!ans.size()) ans += 'Y';

  vector<char> other;
  if(ans == "A"){
    other.pb('B');
    other.pb('X');
    other.pb('Y');
  }
  if(ans == "B"){
    other.pb('A');
    other.pb('X');
    other.pb('Y');
  }
  if(ans == "X"){
    other.pb('B');
    other.pb('A');
    other.pb('Y');
  }
  if(ans == "Y"){
    other.pb('B');
    other.pb('X');
    other.pb('A');
  }

  for(int i = 1; i <= N-2; i++){
     p = "";
     p += (ans + other[1]); // just add other[1]
     p += (ans + other[2] + other[0]);
     p += (ans + other[2] + other[1]);
     p += (ans + other[2] + other[2]);

     int len = press(p);

     if(len == i) ans += other[0];
     else if(len == i + 1) ans += other[1];
     else ans += other[2];
  }

  for(int i = 0; i < 2; i++){
    p = ans + other[i];
    c = press(p);
    if(c == N){
      ans += other[i];
      break;
    }
  }
  if(ans.size() < N) ans += other[2];
  p = ans + ans + ans + ans;
  if(ans.size() < N){
    c = press(p);
  }

  return ans;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:63:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   63 |   if(ans.size() < N) ans += other[2];
      |      ~~~~~~~~~~~^~~
combo.cpp:65:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   65 |   if(ans.size() < N){
      |      ~~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...