Submission #411337

#TimeUsernameProblemLanguageResultExecution timeMemory
411337usachevd0Combo (IOI18_combo)C++14
97 / 100
42 ms572 KiB
#include <bits/stdc++.h> #ifndef LOCAL #include "combo.h" #endif using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define all(a) (a).begin(), (a).end() #define Time (clock() * 1.0 / CLOCKS_PER_SEC) using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pil = pair<int, ll>; using pli = pair<ll, int>; using pll = pair<ll, ll>; using ld = long double; template<typename T1, typename T2> bool chkmin(T1& x, T2 y) { return y < x ? (x = y, true) : false; } template<typename T1, typename T2> bool chkmax(T1& x, T2 y) { return y > x ? (x = y, true) : false; } void debug_out() { cerr << endl; } template<typename T1, typename... T2> void debug_out(T1 A, T2... B) { cerr << ' ' << A; debug_out(B...); } template<typename T> void mdebug_out(T* a, int n) { for (int i = 0; i < n; ++i) cerr << a[i] << ' '; cerr << endl; } #ifdef LOCAL #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__) #define mdebug(a, n) cerr << #a << ": ", mdebug_out(a, n) #else #define debug(...) 1337 #define mdebug(a, n) 1337 #endif template<typename T> ostream& operator << (ostream& stream, const vector<T>& v) { for (auto& x : v) stream << x << ' '; return stream; } template<typename T1, typename T2> ostream& operator << (ostream& stream, const pair<T1, T2>& p) { return stream << p.first << ' ' << p.second; } #ifdef LOCAL mt19937 rng(228); int n; string s; int press(string p) { int mx = 0; for (int i = 0; i < p.size(); ++i) { int lcp = 0; while (lcp < n && i + lcp < p.size() && s[lcp] == p[i + lcp]) ++lcp; chkmax(mx, lcp); } return mx; } #endif const string ch[4] = {"A", "B", "X", "Y"}; // int Press(vector<int> v) { // string s(v.size()); // for (int i = 0; i < v.size(); ++i) // s[i] = ch[v[i]]; // returu press(s); // } string guess_sequence(int n) { mt19937 rng(time(0)); vector<int> ord_z = {0, 1, 2, 3}; shuffle(all(ord_z), rng); int zi = 0; while (zi < 3 && press(ch[ord_z[zi]]) == 0) ++zi; int z = ord_z[zi]; if (n == 1) { return ch[z]; } vector<string> rem; for (int i = 0; i < 4; ++i) if (i != z) rem.push_back(ch[i]); string cur = ch[z]; for (int i = 1; i + 1 < n; ++i) { string q = cur + rem[0] + rem[0] + cur + rem[0] + rem[1] + cur + rem[0] + rem[2] + cur + rem[1]; int res = press(q); if (res == i) { cur += rem[2]; } else if (res == i + 1) { cur += rem[1]; } else { cur += rem[0]; } } vector<int> ord_l = {0, 1, 2}; shuffle(all(ord_l), rng); int li = 0; while (li < 2 && press(cur + rem[ord_l[li]]) < n) ++li; int l = ord_l[li]; cur += rem[l]; return cur; } #ifdef LOCAL int32_t main() { #ifdef LOCAL freopen("in", "r", stdin); #endif ios::sync_with_stdio(0); cin.tie(0); for (int test = 1; ; ++test) { n = 10; int z = rng() % 4; s = ch[z]; vector<string> rem; for (int i = 0; i < 4; ++i) if (i != z) rem.push_back(ch[i]); for (int i = 1; i < n; ++i) s += rem[rng() % 3]; if (guess_sequence(n) != s) { debug(s); exit(0); } if (test % 10000 == 0) debug(test); }/**/ cin >> s; n = s.size(); cout << guess_sequence(n) << '\n'; return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...