Submission #765485

#TimeUsernameProblemLanguageResultExecution timeMemory
765485typ_ikCombo (IOI18_combo)C++17
100 / 100
37 ms624 KiB
#include "combo.h" #include <bits/stdc++.h> #define ll long long #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define watch(x) cout << (#x) << " : " << x << '\n' #define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); using namespace std; //const string hidden = "XYYYYYYY"; // //int press(string s) { // cout << "ask " << s << '\n'; // int res = 0, pt = 0; // for (int i = 0; i < (int)s.size(); i++) { // if (hidden[pt] == s[i]) // pt++; // else // pt = 0; // res = max(res, pt); // if (pt == (int)hidden.size()) // break; // } // return res; //} string make_string(char x) { string res; res += x; return res; } string guess_sequence(int N) { // guess first letter int n = N; const vector<char> symb = {'A', 'B', 'X', 'Y'}; vector <int> order(4); iota(all(order), 0); random_shuffle(all(order)); char blocked = '.'; { int c = press(make_string(symb[order[0]])+make_string(symb[order[1]])); if (c == 0) { c = press(make_string(symb[order[2]])); if (c == 1) blocked = symb[order[2]]; else blocked = symb[order[3]]; } else { c = press(make_string(symb[order[0]])); if (c == 1) blocked = symb[order[0]]; else blocked = symb[order[1]]; } } assert(blocked != '.'); int pos = -1; for (int i = 0; i < 4; i++) if (symb[order[i]] == blocked) pos = i; assert(pos != -1); order.erase(order.begin() + pos); assert((int)order.size() == 3); vector <char> ss; for (auto i : order) ss.push_back(symb[i]); string pref = make_string(blocked); if (n == 1) return pref; for (int i = 1; i + 1 < n; i++) { vector <string> parts; parts.push_back(pref+ss[0]); parts.push_back(pref+ss[1]+ss[0]); parts.push_back(pref+ss[1]+ss[1]); parts.push_back(pref+ss[1]+ss[2]); string tot = ""; for (auto& c : parts) tot += c; assert((int)tot.size() <= 4 * n); int c = press(tot); if (c == i) pref += ss[2]; else if (c == i + 1) pref += ss[0]; else if (c == i + 2) pref += ss[1]; } assert((int)pref.size() == n - 1); int c = press(pref+ss[0]); if (c == n) return pref+ss[0]; c = press(pref+ss[1]); if (c == n) return pref+ss[1]; return pref+ss[2]; } //main() { // srand(time(NULL)); // boost; // // string res = guess_sequence((int)(hidden.size())); // // cout << "res = " << res << '\n'; // cout << (res == hidden ? "correct" : "incorrect") << '\n'; // // return 0; //}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...