Submission #766619

#TimeUsernameProblemLanguageResultExecution timeMemory
766619marvinthangCombo (IOI18_combo)C++17
100 / 100
24 ms756 KiB
/************************************* * author: marvinthang * * created: 26.06.2023 08:55:53 * *************************************/ #include "combo.h" #include <bits/stdc++.h> using namespace std; #define fi first #define se second #define left ___left #define right ___right #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define MASK(i) (1LL << (i)) #define BIT(x, i) ((x) >> (i) & 1) #define __builtin_popcount __builtin_popcountll #define ALL(v) (v).begin(), (v).end() #define REP(i, n) for (int i = 0, _n = (n); i < _n; ++i) #define REPD(i, n) for (int i = (n); i--; ) #define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; ++i) #define FORD(i, b, a) for (int i = (b), _a = (a); --i >= _a; ) #define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i) #define FORDE(i, b, a) for (int i = (b), _a = (a); i >= _a; --i) #define scan_op(...) istream & operator >> (istream &in, __VA_ARGS__ &u) #define print_op(...) ostream & operator << (ostream &out, const __VA_ARGS__ &u) #ifdef LOCAL #include "debug.h" #else #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); } #define DB(...) 23 #define db(...) 23 #define debug(...) 23 #endif template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; } template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; } template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; } template <size_t i, class T> ostream & print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); } template <class ...U> print_op(tuple<U...>) { return print_tuple_utils<0, tuple<U...>>(out, u); } template <class Con, class = decltype(begin(declval<Con>()))> typename enable_if <!is_same<Con, string>::value, ostream&>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; } // end of template string guess_sequence(int N) { string S; if (press("AB")) S += press("A") ? 'A' : 'B'; else S += press("X") ? 'X' : 'Y'; string R; for (char c: {'A', 'B', 'X', 'Y'}) if (c != S[0]) R += c; FOR(i, 2, N) { string a = S + R[0]; for (char c: R) a += S + R[1] + c; int t = press(a); if (t == i) S += R[0]; else if (t == i + 1) S += R[1]; else S += R[2]; } if (N > 1) { REP(i, 2) if (press(S + R[i]) == N) return S + R[i]; return S + R[2]; } return S; } #ifdef LOCAL #include <cstdio> #include <cstdlib> #include <algorithm> #include <string> #include "combo.h" 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 = 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() { file("combo"); char buffer[MAX_N + 1]; if (scanf("%s", buffer) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } S = buffer; N = S.length(); num_moves = 0; std::string answer = guess_sequence(N); if (answer != S) { cout << answer << '\n'; wrong_answer("wrong guess: "); exit(0); } printf("Accepted: %d\n", num_moves); return 0; } #endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...