제출 #1316056

#제출 시각아이디문제언어결과실행 시간메모리
1316056otarius콤보 (IOI18_combo)C++20
100 / 100
9 ms544 KiB
#include "combo.h"
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;

// #pragma GCC optimize("Ofast")
// #pragma GCC optimize ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define ull unsigned long long
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rngl(chrono::steady_clock::now().time_since_epoch().count());

// #define int long long
// #define int unsigned long long

// #define ordered_set(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
// #define ordered_multiset(T) tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>

const ll mod = 1e9 + 7;
// const ll mod = 998244353;

const ll inf = 1e9;
const ll biginf = 1e18;
const int maxN = 4 * 1e5 + 15;

// 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) {
//     cout << p << '\n';
//   if (++num_moves > MAX_NUM_MOVES) {
//     wrong_answer("too many moves");
//   }
//   int len = p.length();
//   if (len > 4 * N) {
//     cout << p; wrong_answer("invalid press");
//   }
//   for (int i = 0; i < len; ++i) {
//     if (p[i] != 'A' && p[i] != 'B' && p[i] != 'X' && p[i] != 'Y') {
//       cout << p; 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 guess_sequence(int n) {
    string s, ans;

    int ret = press("AB");
    if (ret == 2) ans += "AB";
    else if (ret == 1) {
        ret = press("A");
        if (ret == 1) ans += "A";
        else ans += "B";
    } else {
        ret = press("X");
        if (ret == 1) ans += "X";
        else ans += "Y";
    }

    if (ans.size() == n) return ans;

    vector<string> vec;
    if (ans[0] != 'A') vec.pb("A");
    if (ans[0] != 'B') vec.pb("B");
    if (ans[0] != 'X') vec.pb("X");
    if (ans[0] != 'Y') vec.pb("Y");
    

    while (ans.size() + 1 < n) {
        s = ans + vec[0] + ans + vec[1] + vec[0] + ans + vec[1] + vec[1] + ans + vec[1] + vec[2];
        
        int ret = press(s);
        if (ret == (int)ans.size()) ans += vec[2];
        if (ret == (int)ans.size() + 1) ans += vec[0];
        if (ret == (int)ans.size() + 2) ans += vec[1];
    }

    if (press(ans + vec[0]) == n) ans += vec[0];
    else if (press(ans + vec[1]) == n) ans += vec[1];
    else ans += vec[2];


    return ans;
}



// int main() {
//   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;
//     wrong_answer("wrong guess");
//     exit(0);
//   }
//   printf("Accepted: %d\n", num_moves);
//   return 0;
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...