Submission #1339314

#TimeUsernameProblemLanguageResultExecution timeMemory
1339314shiba_ensureCombo (IOI18_combo)C++20
100 / 100
8 ms492 KiB
#include "combo.h"
#include <bits/stdc++.h>
#include <stdio.h>

#define __Shibae__      signed main()
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fiopen(Path)    freopen(Path".INP", "r", stdin); freopen(Path".OUT", "w", stdout);
#define fipen(Path)     freopen(Path".INP", "r", stdin);
#define sz(s)           (int)s.size()
#define all(x)          x.begin(), x.end()
#define maxHeap         priority_queue<int>
#define minHeap         priority_queue<int, vector<int>, greater<int>>
#define getBit(x, k)    (((x) >> (k)) & 1)
#define MASK(i)         (1LL << (i))
#define SQR(x)          (1LL * ((x) * (x)))
#define db              double
#define ld              long double
#define ui              unsigned int
#define ll              long long
#define ii              pair<int, int>
#define pli             pair<ll, int>
#define pil             pair<int, ll>
#define pll             pair<ll, ll>
#define fi              first
#define se              second

#define FOR(i, a, b)    for(int i = a, _b = b; i <= _b; i += 1)
#define FOD(i, a, b)    for(int i = a, _b = b; i >= _b; i -= 1)
#define REP(i, a)       for(int i = 0, _a = a; i < _a; i++)
#define pb              push_back
#define fau(u, a)       for(auto &u : a)
#define debug           return cout << "debug", void();

using namespace std;

const ll mod = 1e9 + 7;
const int INF = 1e9 + 7;
const ll INFLL = (ll)2e18 + 7LL;
const ld PI = acos(-1);
const int MAX = 5e5+5;
 
const int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
const int dy[] = {0, 0, 1, -1, -1, -1, 1, 1};

mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());

ll Rand(ll l, ll r) 
{
    return uniform_int_distribution<ll>(l, r)(rd);
}

template<class SHIBA, class ENGINE>
    bool minimize(SHIBA &x, const ENGINE y)
    {
        if(x > y)
        {
            x = y;
            return true;
        } 
        else return false;
    }
template<class SHIBA, class ENGINE>
    bool maximize(SHIBA &x, const ENGINE y)
    {
        if(x < y)
        {
            x = y;
            return true;
        }
        else return false;
    }


/* Template by: Nguyen Nhat Anh from Luong Van Chanh High School for the gifted */
/* From Min Tuoi with love */
        /**       TRY HARD        **/
        /**          ORZ          **/

/* -----------------[ MAIN CODE ]----------------- */

#ifdef SHABI
#define press check
string s = "YABXBBABBBAAAXAAABBBBBBABAABABAXABBAAXAABBAAX";

int check(string tmp)
{
    FOD(len, (int)min(tmp.size(), s.size()), 1)
    {
        REP(j, tmp.size() - len + 1) if (tmp.substr(j, len) == s.substr(0, len)) return len;
    }
    return 0;
}
#endif


string guess_sequence(int n)
{
    string res;
    vector<string> add;

    if (press("AB") >= 1)
    {
        if (press("A") == 1) res += "A";
        else res += "B";
    }
    else 
    {
        if (press("X") == 1) res += "X";
        else res += "Y";
    }

    if (n == 1) return res;

    if (res[0] != 'A') add.pb("A");
    if (res[0] != 'B') add.pb("B");
    if (res[0] != 'X') add.pb("X");
    if (res[0] != 'Y') add.pb("Y");

    assert(add.size() == 3);

    FOR(i, 2, n-1)
    {
        string tmp = res + add[0] + res + add[1] + add[2] + res + add[1] + add[0] + res + add[1] + add[1];
        int t = press(tmp);
        if (t == res.size()) res += add[2];
        else
        {
            if (res.size() + 2 <= t) res += add[1];
            else res += add[0];
        }
    }

    if (press(res + add[0]) == n) res += add[0];
    else if (press(res + add[1]) == n) res += add[1];
    else res += add[2];
    return res;
}

#ifdef SHABI
__Shibae__
{
    IOS

    cout << guess_sequence(s.size());
 
    return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...