제출 #399160

#제출 시각아이디문제언어결과실행 시간메모리
399160Matteo_Verz콤보 (IOI18_combo)C++17
100 / 100
61 ms464 KiB
#include <bits/stdc++.h> #include "combo.h" using namespace std; string v = "ABXY"; void Guess_Next(string &s, int N) { if(s.size() == N - 1) return; // Will do this very ugly if(s[0] == 'A') { int answ = press(s + "B" + s + "XB" + s + "XY" + s + "XX"); if(answ == s.size() + 1) { s += "B"; Guess_Next(s, N); } else if(answ == s.size() + 2) { s += "X"; Guess_Next(s, N); } else if(answ == s.size()) { s += "Y"; Guess_Next(s, N); } } else if(s[0] == 'B') { int answ = press(s + "A" + s + "XA" + s + "XY" + s + "XX"); if(answ == s.size() + 1) { s += "A"; Guess_Next(s, N); } else if(answ == s.size() + 2) { s += "X"; Guess_Next(s, N); } else if(answ == s.size()) { s += "Y"; Guess_Next(s, N); } } else if(s[0] == 'X') { int answ = press(s + "A" + s + "BA" + s + "BY" + s + "BB"); if(answ == s.size() + 1) { s += "A"; Guess_Next(s, N); } else if(answ == s.size() + 2) { s += "B"; Guess_Next(s, N); } else if(answ == s.size()) { s += "Y"; Guess_Next(s, N); } } else { // s[0] == 'Y' int answ = press(s + "A" + s + "BA" + s + "BX" + s + "BB"); if(answ == s.size() + 1) { s += "A"; Guess_Next(s, N); } else if(answ == s.size() + 2) { s += "B"; Guess_Next(s, N); } else if(answ == s.size()) { s += "X"; Guess_Next(s, N); } } } string guess_sequence(int N) { string ans = ""; // Guessing the first character if(press("AB") > 0) { if(press("A") > 0) ans = "A"; else ans = "B"; } else { // press("XY") > 0 if(press("X") > 0) ans = "X"; else ans = "Y"; } if(N == 1) return ans; if(N > 2) Guess_Next(ans, N); // Guessing the last character string tries = ""; for(int i = 0; i < v.size(); i++) if(v[i] != ans[0]) tries += v[i]; for(int i = 0; i < tries.size() - 1; i++) { if(tries[i] != ans[0] && press(ans + tries[i]) == N) { ans += tries[i]; i = tries.size(); } } if(ans.size() == N - 1) ans += tries.back(); return ans; }

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

combo.cpp: In function 'void Guess_Next(std::string&, int)':
combo.cpp:8:17: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
    8 |     if(s.size() == N - 1) return;
      |        ~~~~~~~~~^~~~~~~~
combo.cpp:15:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |         if(answ == s.size() + 1) {
      |            ~~~~~^~~~~~~~~~~~~~~
combo.cpp:18:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         } else if(answ == s.size() + 2) {
      |                   ~~~~~^~~~~~~~~~~~~~~
combo.cpp:21:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         } else if(answ == s.size()) {
      |                   ~~~~~^~~~~~~~~~~
combo.cpp:28:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |         if(answ == s.size() + 1) {
      |            ~~~~~^~~~~~~~~~~~~~~
combo.cpp:31:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |         } else if(answ == s.size() + 2) {
      |                   ~~~~~^~~~~~~~~~~~~~~
combo.cpp:34:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         } else if(answ == s.size()) {
      |                   ~~~~~^~~~~~~~~~~
combo.cpp:41:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if(answ == s.size() + 1) {
      |            ~~~~~^~~~~~~~~~~~~~~
combo.cpp:44:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         } else if(answ == s.size() + 2) {
      |                   ~~~~~^~~~~~~~~~~~~~~
combo.cpp:47:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         } else if(answ == s.size()) {
      |                   ~~~~~^~~~~~~~~~~
combo.cpp:54:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         if(answ == s.size() + 1) {
      |            ~~~~~^~~~~~~~~~~~~~~
combo.cpp:57:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         } else if(answ == s.size() + 2) {
      |                   ~~~~~^~~~~~~~~~~~~~~
combo.cpp:60:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |         } else if(answ == s.size()) {
      |                   ~~~~~^~~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:88:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     for(int i = 0; i < v.size(); i++)
      |                    ~~^~~~~~~~~~
combo.cpp:92:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |     for(int i = 0; i < tries.size() - 1; i++) {
      |                    ~~^~~~~~~~~~~~~~~~~~
combo.cpp:99:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   99 |     if(ans.size() == N - 1)
      |        ~~~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...