이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "combo.h"
//std::string guess_sequence(int N);
//extern int press(std::string p);
using namespace std;
/*
constexpr int MAX_N = 2000;
constexpr int MAX_NUM_MOVES = 8000;
void wrong_answer(const char *MSG) {
printf("Wrong Answer: %s\n", MSG);
exit(0);
}
std::string S;
int N;
int num_moves;
int press(std::string p) {
if (++num_moves > MAX_NUM_MOVES) {
wrong_answer("too many moves");
}
int len = p.length();
if (len > 4 * N) {
wrong_answer("invalid press");
}
for (int i = 0; i < len; ++i) {
if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
wrong_answer("invalid press");
}
}
int coins = 0;
for (int i = 0, j = 0; i < len; ++i) {
if (j < N && S[j] == p[i]) {
++j;
} else if (S[0] == p[i]) {
j = 1;
} else {
j = 0;
}
coins = std::max(coins, j);
}
return coins;
}
*/
std::string guess_sequence(int N) {
string S;
// 1. Get first element (2 press)
int res = press("AB");
if (res == 0) { // It means X or Y
res = press("X");
if (res == 0) S += "Y";
else S += "X";
}
else {
res = press("A");
if (res == 0) S += "B";
else S += "A";
}
//cout << "Guess: " << S << '\n';
if (N == 1) return S;
// 2. Get second to N - 1 element ( N - 2 press)
char d[5] = "ABXY";
for (int i = 1; i < N - 1; i++) { // first to N - 1, we cannot send exceeding length of 4N
char x = 0, y = 0, z = 0;
for (int j = 0; j < 4; j++) {
if (d[j] == S[0]) continue;
if (x == 0) x = d[j];
else if (y == 0) y = d[j];
else z = d[j];
}
// We can determine i'th char by using this method:
// use delimeter as FIRST CHAR AS THEY DO NOT SHOW OFF ANYMORE
// ALSO IT IS FIRST OF STRING, it stands special
// SxxSxySxzSz
// -> if 2: it has x for first, because we used all x, y, z.
// -> if 1: it has z for first
// -> if 0: it has y for first
string payload = S + x + x + S + x + y + S + x + z + S + z;
res = press(payload);
if (res == S.size() + 2) {
S += x;
}
else if (res == S.size() + 1) {
S += z;
} else {
S += y;
}
//cout << "Guess: " << S << '\n';
}
// 3. Get Last element (2 press)
int tried = 0;
for (int j = 0; j < 4; j++) {
if (d[j] == S[0]) continue;
if (tried == 2) {
S += d[j];
return S;
}
res = press(S + d[j]);
tried++;
if (res == N) {
S += d[j];
return S;
}
}
return S;
}
/*
int main() {
cin >> N >> S;
cout << guess_sequence(N) << '\n';
}
*/
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:91:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
91 | if (res == S.size() + 2) {
| ~~~~^~~~~~~~~~~~~~~
combo.cpp:94:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | else if (res == S.size() + 1) {
| ~~~~^~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |