이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "combo.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ln '\n'
const string B = "ABXY";
string use = "";
string ans = "";
int res;
string add(char a, char b){
string s = "";
s.append(1, a);
s.append(1, b);
return s;
}
void which(int idx){
int a, b;
if (idx == 0) {a = 1; b = 2;}
else if (idx == 1) {a = 0; b = 2;}
else {a = 0; b = 1;}
string s = ans + add(use[idx], use[idx]) + ans + add(use[idx], use[a]);
res = press(s);
if (res == ans.size() + 1) ans += add(use[idx], use[b]);
else {
s = ans + add(use[idx], use[idx]);
res = press(s);
if (res == ans.size() + 1) ans += add(use[idx], use[a]);
else ans += add(use[idx], use[idx]);
}
}
void guess(){
string g1 = ans;
g1.append(2, use[0]);
g1 += ans;
g1.append(1, use[0]); g1.append(1, use[1]);
g1 += ans;
g1.append(1, use[0]); g1.append(1, use[2]);
g1 += ans;
g1.append(1, use[1]); g1.append(1, ans[0]);
res = press(g1);
if (res == ans.size()) which(2);
else if (res == ans.size() + 1) which(1);
else which(0);
}
string guess_sequence(int n){
int i = 0;
if (n & 1){
// press one
for (int i = 0; i < 3; i++){
res = press(B.substr(i, 1));
if (res == 1) {ans += B[i]; break;}
}
if (ans.empty()) ans += B[3];
i++;
} else {
// press two
res = press("AB");
if (res == 2) ans = "AB";
else if (res == 1){
int t = press("BXBY");
if (t == 0){
int t2 = press("AX");
ans = ((t2 == 2)? "AX" : "AY");
} else if (t == 1) ans = "BA";
else {
int t2 = press("BX");
ans = ((t2 == 2)? "BX": "BY");
}
} else {
res = press("XY");
if (res == 2) ans = "XY";
else if (res == 1){
int t = press("YAYB");
if (t == 0){
int t2 = press("XA");
ans = ((t2 == 2)? "XA" : "XB");
} else if (t == 1) ans = "YX";
else {
int t2 = press("YA");
ans = ((t2 == 2)? "YA": "YB");
}
}
}
i += 2;
}
for (int i = 0; i < 4; i++) if (ans[0] != B[i]) use += B[i];
for (; i < n; i += 2) guess();
// cout << ans << ln;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'void which(int)':
combo.cpp:28:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | if (res == ans.size() + 1) ans += add(use[idx], use[b]);
| ~~~~^~~~~~~~~~~~~~~~~
combo.cpp:32:17: 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 (res == ans.size() + 1) ans += add(use[idx], use[a]);
| ~~~~^~~~~~~~~~~~~~~~~
combo.cpp: In function 'void guess()':
combo.cpp:50:13: 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 (res == ans.size()) which(2);
| ~~~~^~~~~~~~~~~~~
combo.cpp:51:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | else if (res == ans.size() + 1) which(1);
| ~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |