제출 #582768

#제출 시각아이디문제언어결과실행 시간메모리
582768TimDee콤보 (IOI18_combo)C++14
100 / 100
31 ms636 KiB
#include "combo.h"

#include <bits/stdc++.h>
using namespace std;

#define forn(i,n) for (int i=0; i<n; ++i)
#define all(a) a.begin(), a.end()
#define pb(x) push_back(x)

std::string guess_sequence(int N) {
    
  int n=N;
  string s;
  //forn(i,n) s+='*';
  char f;
  if (press("AB")) {
    if (press("A")) {
      f='A';
    } else {
      f='B';
    }
  } else {
    if (press("X")) {
      f='X';
    } else {
      f='Y';
    }
  }

  vector<char> v;
  if (f!='A') v.pb('A'); if (f!='B') v.pb('B'); if (f!='X') v.pb('X'); if (f!='Y') v.pb('Y'); 

  s+=f;

  while (s.length()!=N) {

    string p;
    p+=s; p+=v[0]; p+=v[0];
    p+=s; p+=v[0]; p+=v[1];
    p+=s; p+=v[0]; p+=v[2];
    p+=s; p+=v[1];

    if (p.length()>=4*N) {
      p.clear();
      p+=s; p+=v[0];
      int x=press(p);
      if (x==N) return p;
      p.clear();
      p+=s; p+=v[1];
      x=press(p);
      if (x==N) return p;
      p.clear();
      p+=s; p+=v[2];return p;
    }

    int x = press(p);

    if (x==s.length()+2) {

      s+=v[0];

    } else if (x==s.length()+1) {

      s+=v[1];

    } else {

      s+=v[2];

    }

  }

  return s;

}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:31:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   31 |   if (f!='A') v.pb('A'); if (f!='B') v.pb('B'); if (f!='X') v.pb('X'); if (f!='Y') v.pb('Y');
      |   ^~
combo.cpp:31:26: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   31 |   if (f!='A') v.pb('A'); if (f!='B') v.pb('B'); if (f!='X') v.pb('X'); if (f!='Y') v.pb('Y');
      |                          ^~
combo.cpp:35:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   35 |   while (s.length()!=N) {
      |          ~~~~~~~~~~^~~
combo.cpp:43:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   43 |     if (p.length()>=4*N) {
      |         ~~~~~~~~~~^~~~~
combo.cpp:58:10: 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 (x==s.length()+2) {
      |         ~^~~~~~~~~~~~~~
combo.cpp:62:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |     } else if (x==s.length()+1) {
      |                ~^~~~~~~~~~~~~~
combo.cpp:12:7: warning: unused variable 'n' [-Wunused-variable]
   12 |   int n=N;
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...