Submission #1197140

#TimeUsernameProblemLanguageResultExecution timeMemory
1197140nvc2k8Combo (IOI18_combo)C++20
5 / 100
0 ms408 KiB
#include <bits/stdc++.h>
#include "combo.h"
#define TASK "task"
#define INT_LIM (int) 2147483647
#define LL_LIM (long long) 9223372036854775807
#define endl '\n'
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define BIT(i,x) (((i)>>(x))&1)
#define FOR(i,a,b) for(int i = (a); i<=(b); i++)
#define FORD(i,a,b) for(int i = (a); i>=(b); i--)
#define ll long long
#define pii pair<int,int>
using namespace std;
///------------------------------------------///

//int press(string p)
//{
//    return 0;
//}

char binarysearch(int i, string cur)
{
    if (press(cur+"A"+cur+"B")==i)
    {
        if (press(cur+"A")==i) return 'A';
        return 'B';
    }
    if (press(cur+"X")==i) return 'X';
    return 'Y';
}

string guess_sequence(int N)
{
    string ret = "";
    vector<char> digit = {'A', 'B', 'X', 'Y'};

    if (N==3)
    {
        FOR(i, 1, 3)
        {
            for (auto d:digit)
            {
                ret+= d;
                if (press(ret)==i) break;
                ret.pop_back();
            }
        }
        return ret;
    }

    ret+= binarysearch(1, ret);
    if (N==1) return ret;

    char c[3]; int cnt = 0;
    for (auto d:digit) if (d!=ret[0])
    {
        c[cnt++] = d;
    }

    FOR(i, 2, N-1)
    {
        string tmp = ret+c[0]+ret+c[1]+c[0]+ret+c[1]+c[1]+ret+c[1]+c[2];
        int result = press(tmp);
        if (result==i) ret+= c[0];
        else if (result==i+1) ret+= c[1];
        else ret+= c[2];
    }

    ret+= binarysearch(N, ret);

    return ret;
}

//signed main()
//{
//    ///--------------------------///
//    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//    if (fopen(TASK".INP","r")!=NULL)
//    {
//        freopen(TASK".INP","r",stdin);
//        freopen(TASK".OUT","w",stdout);
//    }
//    ///--------------------------///
//
//    int NTEST = 1;
//    //cin >> NTEST;
//
//    return 0;
//}
//
/////------------------------------------------///
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...