Submission #1264622

#TimeUsernameProblemLanguageResultExecution timeMemory
1264622wedonttalkanymoreCombo (IOI18_combo)C++20
97 / 100
7 ms484 KiB
#include "combo.h" #include <bits/stdc++.h> using namespace std; using ll = long long; //#define int long long #define pii pair<ll, ll> #define fi first #define se second const ll MAXX = 2e5 + 5, inf = 1e9, mod = 1e9 + 7, block = 320, lim = 16; //namespace { // //constexpr int MAX_N = 2000; //constexpr int MAX_NUM_MOVES = 8000; // //int N; //std::string S; // //int num_moves = 0; // //void wrong_answer(const char *MSG) { // printf("Wrong Answer: %s\n", MSG); // exit(0); //} //// ////} // namespace //// ////int press(std::string p) { //// cout << p << ' ' << num_moves << '\n'; //// if (++num_moves > MAX_NUM_MOVES) { //// cout << num_moves << '\n'; //// 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; ////} string convert(string &ans, vector <char> &unbanned) { string t = ans; t += unbanned[0]; t += unbanned[0]; t += ans; t += unbanned[0]; t += unbanned[1]; t += ans; t += unbanned[0]; t += unbanned[2]; t += ans; t += unbanned[1]; return t; } map <char, int> mp; string guess_sequence(int N) { mp['A'] = 1, mp['B'] = 2, mp['X'] = 3, mp['Y'] = 4; string ans = ""; int begin = 0; int t = press("AB"); if (t) { int t1 = press("A"); if (t1) ans += "A"; else ans += "B"; if (t1) begin = 1; else begin = 2; } else { int t1 = press("X"); if (t1) ans += "X"; else ans += "Y"; if (t1) begin = 3; else begin = 4; } if ((int)ans.size() == N) return ans; vector <char> unbanned; for (auto i : mp) { if (begin != i.second) unbanned.push_back(i.first); } while((int)ans.size() < N - 1) { string pre = convert(ans, unbanned); int got = press(pre); int base = ans.size(); if (got == base + 2) { ans += unbanned[0]; } else if (got == base + 1) { ans += unbanned[1]; } else if (got == base) { ans += unbanned[2]; } else { bool ok = false; for (char c : unbanned) { string tmp = ans; tmp += c; int r = press(tmp); if (r == base + 1) { ans += c; ok = true; break; } } if (!ok) { vector<char> ALL = {'A','B','X','Y'}; for (char c : ALL) { string tmp = ans; tmp += c; int r = press(tmp); if (r == base + 1) { ans += c; ok = true; break; } } } if (!ok) { ans += unbanned[0]; } } } for (auto i : unbanned) { string tmp = ans; tmp += i; int tt = press(tmp); if (tt == N) return tmp; } vector<char> ALL = {'A','B','X','Y'}; for (char c : ALL) { string tmp = ans; tmp += c; int tt = press(tmp); if (tt == N) return tmp; } ans += unbanned[0]; return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...