Submission #427665

#TimeUsernameProblemLanguageResultExecution timeMemory
427665daanolavCombo (IOI18_combo)C++14
Compilation error
0 ms0 KiB
#include "combo.h" #include <string> using namespace std; string characters[4]; int press(std::string p) { int len = p.length(); int coins = 0; for (int i = 0, j = 0; i < len; ++i) { if (j < N && S[j] == p[i]) { ++j; } else if (S[0] == p[i]) { j = 1; } else { j = 0; } coins = std::max(coins, j); } return coins; } std::string guess_sequence(int N) { characters[0] = "A"; characters[1] = "B"; characters[2] = "X"; characters[3] = "Y"; string start = ""; int res = press("AB"); if(res >= 1) { if(res == 2) { start = "AB"; } else { res = press("AX"); if(res == 0) { start = "B"; } else if(res == 1) { start = "A"; } else { start = "AX"; } } } else { res = press("XA"); if(res == 0) { start = "Y"; } else if(res == 1) { start = "X"; } else { start = "XA"; } } string first = "" + start.substr(0,1); string notFirst[3]; int i = 0; for(string c : characters) { if(first == c) { continue; } notFirst[i] = c; ++i; } while(start.size() != N) { res = press(start + notFirst[0] + start + notFirst[1] + notFirst[0]); if(res == start.size()) { start = start + notFirst[2]; } else if(res == start.size() + 2) { start = start + notFirst[1] + notFirst[0]; } else { res = press(start + notFirst[0] + notFirst[0]); if(res == start.size()) { start = start + notFirst[1]; } else if(res == start.size() + 2) { start = start + notFirst[0] + notFirst[0]; } else { start = start + notFirst[0]; } } } return start; }

Compilation message (stderr)

combo.cpp: In function 'int press(std::string)':
combo.cpp:14:13: error: 'N' was not declared in this scope
   14 |     if (j < N && S[j] == p[i]) {
      |             ^
combo.cpp:14:18: error: 'S' was not declared in this scope
   14 |     if (j < N && S[j] == p[i]) {
      |                  ^
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:70:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |     while(start.size() != N) {
      |           ~~~~~~~~~~~~~^~~~
combo.cpp:72:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |         if(res == start.size()) {
      |            ~~~~^~~~~~~~~~~~~~~
combo.cpp:74:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         } else if(res == start.size() + 2) {
      |                   ~~~~^~~~~~~~~~~~~~~~~~~
combo.cpp:78:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   78 |             if(res == start.size()) {
      |                ~~~~^~~~~~~~~~~~~~~
combo.cpp:80:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |             } else if(res == start.size() + 2) {
      |                       ~~~~^~~~~~~~~~~~~~~~~~~