제출 #96124

#제출 시각아이디문제언어결과실행 시간메모리
96124kitsu_hi콤보 (IOI18_combo)C++14
컴파일 에러
0 ms0 KiB
#include "combo.h"
#include <bits/stdc++.h> 
using namespace std;

string guess_sequence(int N) {
  string ans;
  ans.clear();
  if ( press("AB") ) {
    if ( press("A") ) ans += 'A';
    else ans += 'B';
  }
  else {
    if ( press("X") ) ans += 'X';
    else ans += 'Y';
  }
  if ( N == 1 )  return ans;
  
  char frst = ans[0];
   char c[4];
  if ( frst == 'A' ) {
      c[1] = 'B';
      c[2] = 'X';
      c[3] = 'Y';
    }
  if ( frst == 'B' ) {
      c[1] = 'A';
      c[2] = 'X';
      c[3] = 'Y';
  }
  if ( frst == 'X' ) {
    c[1] = 'A';
    c[2] = 'B';
    c[3] = 'Y';
  }
  if ( frst == 'Y' ) {
    c[1] = 'A';
    c[2] = 'B';
    c[3] = 'X';
  }
  
  for ( int i = 2 ; i < N; i++ ) {
    string ct;
    ct.clear();
    for ( int i = 1; i <= 3; i++ ) {
      ct = ct + ans + c[1] + c[i];
    }
    ct = ct + ans + c[2];
    switch( press(ct) ) {
      case i - 1: 
        ans += c[3];
        break;
      case i:
        ans += c[2];
        break;
      case i + 1: 
        ans += c[3];
        break;
    }
  }
  if ( press( ans + c[1] + ans + c[2] ) == N ) {
    if ( press( ans + c[1]) == N ) ans += c[1];
    else ans += c[2];
  }
  else {
    ans += c[3];
  }
  return ans;
}

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:49:16: error: the value of 'i' is not usable in a constant expression
   49 |       case i - 1:
      |                ^
combo.cpp:41:13: note: 'int i' is not const
   41 |   for ( int i = 2 ; i < N; i++ ) {
      |             ^
combo.cpp:49:12: error: the value of 'i' is not usable in a constant expression
   49 |       case i - 1:
      |            ^
combo.cpp:41:13: note: 'int i' is not const
   41 |   for ( int i = 2 ; i < N; i++ ) {
      |             ^
combo.cpp:52:12: error: the value of 'i' is not usable in a constant expression
   52 |       case i:
      |            ^
combo.cpp:41:13: note: 'int i' is not const
   41 |   for ( int i = 2 ; i < N; i++ ) {
      |             ^
combo.cpp:52:12: error: the value of 'i' is not usable in a constant expression
   52 |       case i:
      |            ^
combo.cpp:41:13: note: 'int i' is not const
   41 |   for ( int i = 2 ; i < N; i++ ) {
      |             ^
combo.cpp:55:16: error: the value of 'i' is not usable in a constant expression
   55 |       case i + 1:
      |                ^
combo.cpp:41:13: note: 'int i' is not const
   41 |   for ( int i = 2 ; i < N; i++ ) {
      |             ^
combo.cpp:55:12: error: the value of 'i' is not usable in a constant expression
   55 |       case i + 1:
      |            ^
combo.cpp:41:13: note: 'int i' is not const
   41 |   for ( int i = 2 ; i < N; i++ ) {
      |             ^