Submission #839651

#TimeUsernameProblemLanguageResultExecution timeMemory
839651sleepntsheep콤보 (IOI18_combo)C++17
0 / 100
1 ms332 KiB
#include "combo.h"
#include <cassert>
#include <string>
#include <vector>
using namespace std;

string guess_sequence(int N)
{
    string ans(2, 0);
    int j = 0, fst = -1, C = 0;
    int non[2005][4] = {0};

    for (int i = 0; i < 4 && !j; ++i)
    {
        if (i == 3) ans[0] = 'Y', ++j;
        else
        {
            int g2i = i ? 0 : 1;

            ans[0] = "ABXY"[i];
            ans[1] = "ABXY"[g2i];

            int k = press(ans); ++C;
            if (k == 1) fst = i, j = 1, non[1][g2i] = 1;
            if (k == 2) fst = i, j = 2;
        }
    }

    /* 3 + (N-2) * 2 + 2 = 5 + 2 N - 4  = 2 N + 1 */

    for (int j = 1; j < N; ++j) non[j][fst] = 1;

    int st = -1;
    for (int nxt, i = j; i < N - 1; i = nxt)
    {
        nxt = i + 1;
        for (int j = 0; j < 4; j++)
        {
            if (non[i][j]) continue;
            if (j == 3) ans[i] = 'Y';
            else
            {
                ans.resize(i+2);

                int g2i = -1;
                for (int k = 0; k < 4; ++k) if (!(non[i+1][k])) { g2i = k; break; }

                ans[i] = "ABXY"[j];
                ans[i+1] = "ABXY"[g2i];

                int k = press(ans); ++C;
                st = -1;
                if (k == i + 1) non[i+1][g2i] = 1;
                if (k == i + 2) { st = 2; nxt = i + 2; }
                if (k >= i + 1) break;
            }
        }
    }

    ans.resize(N);
    if (st == -1)
    {
        for (int j = 0; j < 4; j++)
        {
            if (non[N-1][j]) continue;
            if (j == 3) ans[N-1] = 'Y';
            else
            {
                ans[N-1] = "ABXY"[j];
                int k = press(ans); ++C;
                if (k == N) break;
            }
        }
    }

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...