이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
// string s= "XB";
// int guesses{};
// int idx=0;
// vector<string> strings {
// "ABB", "ABX", "ABY", "AXB", "AXX", "AXY", "AYB", "AYX", "AYY",
// "BAA", "BAX", "BAY", "BXA", "BXX", "BXY", "BYA", "BYX", "BYY",
// "XAA", "XAB", "XAY", "XBA", "XBB", "XBY", "XYA", "XYB", "XYY",
// "YAA", "YAB", "YAX", "YBA", "YBB", "YBX", "YXA", "YXB", "YXX",
// };
int press(string p);
// {
// string s=strings[idx];
// guesses++;
// int ans{};
// for (auto i=0;i<p.size();i++) {
// for (auto j=i;(j<p.size())&&((j-i)<s.size())&&(p[j]==s[j-i]);j++) {
// ans=max(ans, j-i+1);
// }
// }
// return ans;
// }
string guess_sequence(int N) {
// figure out the first letter
if (N==1) {
if (press("A")==1) return "A";
else if (press("B")==1) return "B";
else if (press("X")==1) return "X";
else return "Y";
}
char first={};
auto res=press("AB");
if (res==2) {
first='A';
}
else if (res==1) {
if (press("A")==1)
first='A';
else
first='B';
}
else if (press("X"))
first='X';
else
first='Y';
string ans{};
ans+=first;
for (int i=1;i<N-1;i++) {
if (first=='A') {
string ask=ans+'X'+first+ans+"YB"+ans+"YY"+ans+"YX";
auto res=press(ask);
//cout << "i="<<i<<",ans="<<ans<<endl;
if (res==ans.size())
{
// B
ans+='B';
}
else if(res==ans.size()+1)
{
ans+='X';
}
else
{
ans+='Y';
}
}
else if (first=='B') {
string ask=ans+'X'+first+ans+"YA"+ans+"YY"+ans+"YX";
auto res=press(ask);
if (res==ans.size())
{
ans+='A';
}
else if(res==ans.size()+1)
{
ans+='X';
}
else
{
ans+='Y';
}
}
else if (first=='X') {
string ask=ans+'A'+first+ans+"YB"+ans+"YY"+ans+"YA";
auto res=press(ask);
if (res==ans.size())
{
ans+='B';
}
else if(res==ans.size()+1)
{
ans+='A';
}
else
{
ans+='Y';
}
}
else if (first=='Y') {
string ask=ans+'A'+first+ans+"XB"+ans+"XA"+ans+"XX";
auto res=press(ask);
if (res==ans.size())
{
ans+='B';
}
else if(res==ans.size()+1)
{
ans+='A';
}
else
{
ans+='X';
}
}
}
if (first=='A') {
if (press(ans+'B')==ans.size()+1) {
ans+='B';
}
else if (press(ans+'X')==ans.size()+1)
{
ans+='X';
}
else ans+='Y';
}
else if (first=='B') {
if (press(ans+'A')==ans.size()+1) {
ans+='A';
}
else if (press(ans+'X')==ans.size()+1)
{
ans+='X';
}
else ans+='Y';
}
else if (first=='X') {
if (press(ans+'B')==ans.size()+1) {
ans+='B';
}
else if (press(ans+'A')==ans.size()+1)
{
ans+='A';
}
else ans+='Y';
}
else if (first=='Y') {
if (press(ans+'B')==ans.size()+1) {
ans+='B';
}
else if (press(ans+'X')==ans.size()+1)
{
ans+='X';
}
else ans+='A';
}
return ans;
}
// auto main() -> int {
// for (auto i=0;i<strings.size();i++) {
// if (strings[i] != guess_sequence(3)) {
// cout << "ERROR: " << guess_sequence(3) << ", EXPECTED: " << strings[i] << endl;
// return 0;
// }
// else cout << "OK" << endl;
// idx++;
// }
// }
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:68:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | if (res==ans.size())
| ~~~^~~~~~~~~~~~
combo.cpp:73:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | else if(res==ans.size()+1)
| ~~~^~~~~~~~~~~~~~
combo.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | if (res==ans.size())
| ~~~^~~~~~~~~~~~
combo.cpp:89:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | else if(res==ans.size()+1)
| ~~~^~~~~~~~~~~~~~
combo.cpp:101:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
101 | if (res==ans.size())
| ~~~^~~~~~~~~~~~
combo.cpp:105:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
105 | else if(res==ans.size()+1)
| ~~~^~~~~~~~~~~~~~
combo.cpp:117:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
117 | if (res==ans.size())
| ~~~^~~~~~~~~~~~
combo.cpp:121:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
121 | else if(res==ans.size()+1)
| ~~~^~~~~~~~~~~~~~
combo.cpp:133:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
133 | if (press(ans+'B')==ans.size()+1) {
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:136:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
136 | else if (press(ans+'X')==ans.size()+1)
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:144:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
144 | if (press(ans+'A')==ans.size()+1) {
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:147:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
147 | else if (press(ans+'X')==ans.size()+1)
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:155:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
155 | if (press(ans+'B')==ans.size()+1) {
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:158:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
158 | else if (press(ans+'A')==ans.size()+1)
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:166:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
166 | if (press(ans+'B')==ans.size()+1) {
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
combo.cpp:169:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
169 | else if (press(ans+'X')==ans.size()+1)
| ~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |