제출 #716896

#제출 시각아이디문제언어결과실행 시간메모리
716896Desh03콤보 (IOI18_combo)C++17
100 / 100
34 ms576 KiB
#include <bits/stdc++.h> #include "combo.h" using namespace std; string guess_sequence(int n) { char first; string s; int x = press("AB"); if (x == 2) { s = "AB"; first = 'A'; } else if (x) { int y = press("A"); if (y) first = 'A', s = "A"; else first = 'B', s = "B"; } else { int y = press("X"); if (y) first = 'X', s = "X"; else first = 'Y', s = "Y"; } while (1) { if (s.size() == n) return s; else if (s.size() <= n - 2) { if (first == 'A') { string p = s + "BB" + s + "BX" + s + "BY" + s + "X"; int y = press(p), sz = s.size(); if (y == sz + 2) { s.push_back('B'); } else if (y == sz + 1) { s.push_back('X'); } else s.push_back('Y'); } else if (first == 'B') { string p = s + "AA" + s + "AX" + s + "AY" + s + "X"; int y = press(p), sz = s.size(); if (y == sz + 2) { s.push_back('A'); } else if (y == sz + 1) { s.push_back('X'); } else s.push_back('Y'); } else if (first == 'X') { string p = s + "BB" + s + "BA" + s + "BY" + s + "A"; int y = press(p), sz = s.size(); if (y == sz + 2) { s.push_back('B'); } else if (y == sz + 1) { s.push_back('A'); } else s.push_back('Y'); } else { string p = s + "BB" + s + "BA" + s + "BX" + s + "A"; int y = press(p), sz = s.size(); if (y == sz + 2) { s.push_back('B'); } else if (y == sz + 1) { s.push_back('A'); } else s.push_back('X'); } } else { if (first == 'A') { string p = s + "B" + s + "X"; int y = press(p); if (y == n - 1) { s.push_back('Y'); } else { p = s + "B"; y = press(p); if (y == n - 1) { s.push_back('X'); } else s.push_back('B'); } } else if (first == 'B') { string p = s + "A" + s + "X"; int y = press(p); if (y == n - 1) { s.push_back('Y'); } else { p = s + "A"; y = press(p); if (y == n - 1) { s.push_back('X'); } else s.push_back('A'); } } else if (first == 'X') { string p = s + "B" + s + "A"; int y = press(p); if (y == n - 1) { s.push_back('Y'); } else { p = s + "B"; y = press(p); if (y == n - 1) { s.push_back('A'); } else s.push_back('B'); } } else { string p = s + "B" + s + "A"; int y = press(p); if (y == n - 1) { s.push_back('X'); } else { p = s + "B"; y = press(p); if (y == n - 1) { s.push_back('A'); } else s.push_back('B'); } } } } }

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

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:21:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         if (s.size() == n) return s;
      |             ~~~~~~~~~^~~~
combo.cpp:22:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   22 |         else if (s.size() <= n - 2) {
      |                  ~~~~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...