제출 #867560

#제출 시각아이디문제언어결과실행 시간메모리
867560Dec0Dedd콤보 (IOI18_combo)C++14
0 / 100
33 ms1700 KiB
#include <bits/stdc++.h>
#include "combo.h"

using namespace std;

// A, B, X, Y

string strend(string s, int n) {
    while ((int)s.size() < n) s+=s[0];
    return s;
}

string guess_sequence(int n) {
    string ans;

    vector<string> v={"A", "B", "X", "Y"};
    if (press("AB") > 0) {
        if (press("A") > 0) ans+="A";
        else ans+="B";
    } else {
        if (press("X") > 0) ans+="X";
        else ans+="Y";
    }

    for (int j=0; j<4; ++j) {
        if (v[j] == string(1, ans[0])) {
            v.erase(v.begin()+j);
            break;
        }
    }

    for (int i=1; i+1<n; ++i) {
        string tmp=strend(ans+v[0]+v[0], n)+strend(ans+v[0]+v[1], n)+strend(ans+v[1]+v[0], n);
        int k=press(tmp)-i;

        if (k == 0) {
            ans+=v[2];
            continue;
        } else if (k == 1) {
            tmp=strend(ans+v[0]+v[0], n);
            int x=press(tmp)-i;

            if (x == 0) ans+=v[1]+v[0];
            else if (x == 1) ans+=v[0]+v[1];
            else ans+=v[0]+v[0];
            ++i;
        } else if (k == 2) {
            tmp=strend(ans+v[0]+v[0], n);
            int x=press(tmp)-i;

            if (x == 0) ans+=v[1]+v[0];
            else if (x == 1) ans+=v[0]+v[1];
            else ans+=v[0]+v[0];
            ++i;
        }
    }

    assert(n-ans.size() <= 1);
    if ((int)ans.size() < n) {
        if (press(ans+v[0]) == n) ans+=v[0];
        else if (press(ans+v[1]) == n) ans+=v[1];
        else ans+=v[2];
    }

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