# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
588139 | evenvalue | Combo (IOI18_combo) | C++17 | 0 ms | 0 KiB |
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;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag,
tree_order_statistics_node_update>;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T> using max_heap = priority_queue<T, vector<T>, less<T>>;
using int64 = long long;
using ld = long double;
constexpr int kInf = 1e9 + 10;
constexpr int64 kInf64 = 1e15 + 10;
constexpr int kMod = 1e9 + 7;
string ans = "A";
int moves = 0;
void check(const string &guess, bool final = false) {
moves++;
if (moves > ans.length() + 2 + 1) {
cout << "too many moves for " << ans << '\n';
exit(0);
} else if (guess.size() > 4 * (int)ans.size()) {
cout << "invalid press";
exit(0);
} else if (final and guess != ans) {
cout << "wrong answer";
cout << "Your guess: " << guess << '\n';
exit(0);
} else if (final) {
cout << "Got correct answer in " << moves - 1 << " moves\n";
return;
} else {
return;
}
}
int press(const string &guess) {
check(guess);
for (int len = ans.length(); len > 0; len--) {
for (int i = 0; i + len <= guess.size(); i++) {
if (guess.substr(i, len) == ans.substr(0, len)) {
return len;
}
}
}
return 0;
// cout << guess << '\n';
// int x;
// cin >> x;
// return x;
}
string convert(string guess) {
for (char &c : guess) {
c = (c == '1' ? 'A' : c);
c = (c == '2' ? 'B' : c);
c = (c == '3' ? 'X' : c);
c = (c == '4' ? 'Y' : c);
}
return guess;
}
int call_press(string s) { return press(convert(std::move(s))); }
string guess_sequence(const int N) {
string s = "-";
if (const int x = call_press("12"); x == 0) {
s[0] = (call_press("3") ? '3' : '4');
} else {
s[0] = (call_press("1") ? '1' : '2');
}
if (N == 1)
return convert(s);
string choices;
for (char c = '1'; c <= '4'; c++) {
if (c == s[0])
continue;
choices += c;
}
for (int i = 1; i < N - 1; i++) {
string guess;
for (int j = 0; j < 3; j++) {
guess += s + choices[0] + choices[j];
}
guess += s + choices[1];
if (const int x = call_press(guess); x == s.size()) {
s.push_back(choices[2]);
} else if (x == s.size() + 1) {
s.push_back(choices[1]);
} else {
s.push_back(choices[0]);
}
}
if (call_press(s + choices[0]) == N) {
s += choices[0];
} else if (call_press(s + choices[1]) == N) {
s += choices[1];
} else {
s += choices[2];
}
return convert(s);
}
void reset() {
ans = "";
moves = 0;
}
int main() {
random_device rd;
uniform_int_distribution<int> u(1, 4);
for (int len = 1000; len < 1001; len++) {
string s(len, '-');
for (int i = 0; i < len; i++) {
s[i] = u(rd) + '0';
}
ans = convert(s);
guess_sequence(ans.length());
reset();
}
}