이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include"combo.h"
using namespace std;
string guess_sequence(int n) {
vector<char> possible = {'A','B','X','Y'};
char first = possible.back();
int cnt = 1;
for(int i=0; i<3; i++) {
char c = possible[i];
int sz = press(string(n, c));
if(sz > 0) {
cnt = sz;
first = c;
break;
}
}
string res = string(cnt, first);
possible.erase(find(possible.begin(), possible.end(), first));
auto allpossible = possible;
while(res.size() < n) {
if(possible.size() == 2) {
int cur = possible[1];
int cnt = 1;
int sz = press(res + string(n, possible[0]));
bool is0 = false;
if(sz > res.size()) {
cur = possible[0];
cnt = sz-res.size();
is0 = true;
}
res += string(cnt, cur);
possible = allpossible;
if(is0) {
possible.erase(find(possible.begin(), possible.end(), cur));
}
} else {
int sz = press(res + string(n, possible[0]) + res + string(n, possible[1]));
if(sz == res.size()) {
res += possible[2];
possible = allpossible;
} else {
int id = 1;
if(press(res + string(n, possible[0])) > res.size()) {
id = 0;
}
res += string(sz-res.size(), possible[id]);
possible = allpossible;
possible.erase(find(possible.begin(), possible.end(), possible[id]));
}
}
}
return res;
}
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:24:22: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
24 | while(res.size() < n) {
| ~~~~~~~~~~~^~~
combo.cpp:32:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(sz > res.size()) {
| ~~~^~~~~~~~~~~~
combo.cpp:45:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if(sz == res.size()) {
| ~~~^~~~~~~~~~~~~
combo.cpp:50:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | if(press(res + string(n, possible[0])) > res.size()) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |