이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |