This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma region dalykai
template <typename F>
void _debug(F f)
{
f();
}
#ifndef _AAAAAAAAA
#define debug(x)
#else
#define debug(x) _debug(x)
#endif
using p32 = pair<int, int>;
using p32u = pair<uint32_t, uint32_t>;
using p64 = pair<int64_t, int64_t>;
using p64u = pair<uint64_t, uint64_t>;
using vi16 = vector<int16_t>;
using vi16u = vector<uint16_t>;
using vi32 = vector<int>;
using vi32u = vector<uint32_t>;
using vi64 = vector<int64_t>;
using vi64u = vector<uint64_t>;
using vp32 = vector<p32>;
using vp32u = vector<p32u>;
using vp64 = vector<p64>;
using vp64u = vector<p64u>;
using vvi32 = vector<vi32>;
using vvi32u = vector<vi32u>;
using vvi64 = vector<vi64>;
using vvi64u = vector<vi64u>;
using vvp32 = vector<vp32>;
using vvp32u = vector<vp32u>;
using vvp64 = vector<vp64>;
using vvp64u = vector<vp64u>;
using f80 = long double;
#pragma endregion
#ifndef _AAAAAAAAA
#include "combo.h"
#else
std::string guess_sequence(int N);
int press(std::string p);
#endif
void guess_separator(string s, char &c)
{
if (s.size() == 1)
{
c = s[0];
return;
}
string l = s.substr(0, s.size() / 2);
string r = s.substr(s.size() / 2, s.size() / 2);
if (press(l))
{
guess_separator(l, c);
}
else
{
guess_separator(r, c);
}
}
std::string guess_sequence(int N)
{
char separator = 0;
string button = "ABXY";
guess_separator(button, separator);
button.erase(find(button.begin(), button.end(), separator));
string result;
result += separator;
for (int i = 2; i < N; i++)
{
// trys zuikiai vienu suviu?
string guess = result + button[0] + button[0];
guess += result + button[0] + button[1];
guess += result + button[0] + button[2];
guess += result + button[1];
int answer = press(guess);
if (answer == i + 1)
{
result += button[0];
}
else if (answer == i)
{
result += button[1];
}
else
{
result += button[2];
}
}
if (result.size() < N)
{
vector<string> q(2);
q[0] = result + button[0];
q[1] = result + button[1];
if (press(q[0] + q[1]) == N)
{
if (press(q[0]) == N)
{
result += button[0];
}
else
{
result += button[1];
}
}
else
{
result += button[2];
}
}
return result;
}
#ifdef _AAAAAAAAA
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 = (int)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()
{
freopen("combo.in", "r", stdin);
char buffer[MAX_N + 1];
if (scanf("%s", buffer) != 1)
{
fprintf(stderr, "Error while reading input\n");
exit(1);
}
S = buffer;
N = (int)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);
return 0;
}
#endif
Compilation message (stderr)
combo.cpp:8: warning: ignoring '#pragma region dalykai' [-Wunknown-pragmas]
8 | #pragma region dalykai
|
combo.cpp:43: warning: ignoring '#pragma endregion ' [-Wunknown-pragmas]
43 | #pragma endregion
|
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:107:23: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
107 | if (result.size() < N)
| ~~~~~~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |