제출 #171176

#제출 시각아이디문제언어결과실행 시간메모리
171176AlexLuchianov콤보 (IOI18_combo)C++14
100 / 100
68 ms608 KiB
#include "combo.h"
#include <iostream>

std::string guess_brute(int N, std::string start){
  if(start.size() < press(start + "A" + start + "B")){
    if(start.size() < press(start + "A"))
      return start + "A";
    else
      return start + "B";
  } else {
    if(start.size() < press(start + "X"))
      return start + "X";
    else
      return start + "Y";
  }
}

std::string guess_smart(int N, std::string start){
  char allowed[3];
  if(start[0] == 'A'){
    allowed[0] = 'B';
    allowed[1] = 'X';
    allowed[2] = 'Y';
  } else if(start[0] == 'B'){
    allowed[0] = 'A';
    allowed[1] = 'X';
    allowed[2] = 'Y';
  } else if(start[0] == 'X'){
    allowed[0] = 'A';
    allowed[1] = 'B';
    allowed[2] = 'Y';
  } else if(start[0] == 'Y'){
    allowed[0] = 'A';
    allowed[1] = 'B';
    allowed[2] = 'X';
  }
  std::string test = start + allowed[1] + start + allowed[2] + allowed[0] + start + allowed[2] + allowed[1] + start + allowed[2] + allowed[2];
  int result = press(test);
  if(result == start.size())
    return start + allowed[0];
  else if(result == start.size() + 1)
    return start + allowed[1];
  else
    return start + allowed[2];
}

std::string guess_sequence(int N) {
  std::string start;
  start = guess_brute(N, start);
  for(int i = 2;i < N; i++)
    start = guess_smart(N, start);
  if(1 < N)
    start = guess_brute(N, start);
  return start;
}

컴파일 시 표준 에러 (stderr) 메시지

combo.cpp: In function 'std::string guess_brute(int, std::string)':
combo.cpp:5:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    5 |   if(start.size() < press(start + "A" + start + "B")){
      |      ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
combo.cpp:6:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    6 |     if(start.size() < press(start + "A"))
      |        ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
combo.cpp:11:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   11 |     if(start.size() < press(start + "X"))
      |        ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
combo.cpp: In function 'std::string guess_smart(int, std::string)':
combo.cpp:39:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   if(result == start.size())
      |      ~~~~~~~^~~~~~~~~~~~~~~
combo.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |   else if(result == start.size() + 1)
      |           ~~~~~~~^~~~~~~~~~~~~~~~~~~
combo.cpp:37:141: warning: 'allowed[2]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |   std::string test = start + allowed[1] + start + allowed[2] + allowed[0] + start + allowed[2] + allowed[1] + start + allowed[2] + allowed[2];
      |                                                                                                                                             ^
combo.cpp:37:107: warning: 'allowed[1]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |   std::string test = start + allowed[1] + start + allowed[2] + allowed[0] + start + allowed[2] + allowed[1] + start + allowed[2] + allowed[2];
      |                                                                                                           ^
combo.cpp:37:73: warning: 'allowed[0]' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |   std::string test = start + allowed[1] + start + allowed[2] + allowed[0] + start + allowed[2] + allowed[1] + start + allowed[2] + allowed[2];
      |                                                                         ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...