이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <cstring>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#define FOR(var,bound) for(int var = 0; var < bound; var++)
#define FORB(var,lb,ub) for (int var = lb; var < ub; var++)
#define FORR(var,bound) for(int var = bound-1; var >= 0; var--)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;
int press(string p);
string guess_sequence(int n) {
string curr;
vector<string> others;
if (press("AB")) {
if (press("A")) {
curr = "A";
others = {"B", "X", "Y"};
} else {
curr = "B";
others = {"A", "X", "Y"};
}
} else if (press("X")) {
curr = "X";
others = {"A", "B", "Y"};
} else {
curr = "Y";
others = {"A", "B", "X"};
}
while (curr.length() < n - 1) {
int res = press(
curr + others[0] +
curr + others[1] + others[0] +
curr + others[1] + others[1] +
curr + others[1] + others[2]
) - curr.size();
if (res == 0) {
curr += others[2];
} else if (res == 1) {
curr += others[0];
} else {
curr += others[1];
}
}
if (press(curr + others[0]) == n) {
curr += others[0];
} else if (press(curr + others[1]) == n) {
curr += others[1];
} else {
curr += others[2];
}
return curr;
}
#ifdef LOCAL_TEST
namespace {
constexpr int MAX_N = 2000;
constexpr int MAX_NUM_MOVES = 8000;
int N;
std::string S;
int num_moves;
void wrong_answer(const char *MSG) {
printf("Wrong Answer: %s\n", MSG);
exit(0);
}
} // namespace
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;
}
int main() {
char buffer[MAX_N + 1];
if (scanf("%s", buffer) != 1) {
fprintf(stderr, "Error while reading input\n");
exit(1);
}
S = buffer;
N = S.length();
num_moves = 0;
std::string answer = guess_sequence(N);
if (answer != S) {
wrong_answer("wrong guess");
exit(0);
}
printf("Accepted: %d\n", num_moves);
if (num_moves <= N + 2) {
printf("Big Win!!!!\n");
} else {
printf("Not 100% :(\n");
}
return 0;
}
#endif
컴파일 시 표준 에러 (stderr) 메시지
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:46:26: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | while (curr.length() < n - 1) {
| ~~~~~~~~~~~~~~^~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |