이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "combo.h"
using namespace std;
// Makes 2 calls & adds on average 2 letters
inline void checkFor(string &s, char a, char b, char c) {
int r = press(s + a + a + s + a + b + s + b + a), r2;
if (s.size() + 1 == r) {
r2 = press(s + b + b);
if (r2 == s.size() + 1) s = s + b + c;
else if (r2 == s.size()) s = s + a + c;
else s = s + b + b;
}
else if (s.size() == r) s += c;
else {
r2 = press(s + a + a);
if (r2 == s.size()) s = s + b + a;
else if (r2 == s.size() + 1) s = s + a + b;
else s = s + a + a;
}
}
inline void checkFinal(string &s, char a, char b, char c) {
if (press(s + a) > s.size()) s += a;
else if (press(s + b) > s.size()) s += b;
else s += c;
}
// Should make N+2 calls
string guess_sequence(int n) {
string s;
// Should make 2 calls
if (press("AB")) { // 1st call
if (press("A")) s = "A"; // 2nd call
else s = "B";
}
else if (press("X")) s = "X"; // 2nd call
else s = "Y";
// Should make N calls
while (s.size() < n - 1) {
if (s[0] == 'A') checkFor(s, 'B', 'X', 'Y');
else if (s[0] == 'B') checkFor(s, 'A', 'X', 'Y');
else if (s[0] == 'X') checkFor(s, 'A', 'B', 'Y');
else if (s[0] == 'Y') checkFor(s, 'A', 'B', 'X');
}
if (s.size() < n) {
if (s[0] == 'A') checkFinal(s, 'B', 'X', 'Y');
else if (s[0] == 'B') checkFinal(s, 'A', 'X', 'Y');
else if (s[0] == 'X') checkFinal(s, 'A', 'B', 'Y');
else if (s[0] == 'Y') checkFinal(s, 'A', 'B', 'X');
}
return s;
}
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'void checkFor(std::string&, char, char, char)':
combo.cpp:6:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
6 | if (s.size() + 1 == r) {
| ~~~~~~~~~~~~~^~~~
combo.cpp:8:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
8 | if (r2 == s.size() + 1) s = s + b + c;
| ~~~^~~~~~~~~~~~~~~
combo.cpp:9:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
9 | else if (r2 == s.size()) s = s + a + c;
| ~~~^~~~~~~~~~~
combo.cpp:12:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
12 | else if (s.size() == r) s += c;
| ~~~~~~~~~^~~~
combo.cpp:15:16: 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 (r2 == s.size()) s = s + b + a;
| ~~~^~~~~~~~~~~
combo.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | else if (r2 == s.size() + 1) s = s + a + b;
| ~~~^~~~~~~~~~~~~~~
combo.cpp: In function 'void checkFinal(std::string&, char, char, char)':
combo.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if (press(s + a) > s.size()) s += a;
| ~~~~~~~~~~~~~^~~~~~~~~~
combo.cpp:22:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | else if (press(s + b) > s.size()) s += b;
| ~~~~~~~~~~~~~^~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:36:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
36 | while (s.size() < n - 1) {
| ~~~~~~~~~^~~~~~~
combo.cpp:42:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
42 | if (s.size() < n) {
| ~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |