Submission #526739

#TimeUsernameProblemLanguageResultExecution timeMemory
526739lcs147Combo (IOI18_combo)C++17
Compilation error
0 ms0 KiB


string guess_sequence(int n) {
    vector<char> possible  = {'A','B','X','Y'};
    
    char first = possible.back();
    int cnt = 1;
    for(int i=0; i<3; i++) {
        char c = possible[i];
        int sz = press(string(n, c));
        if(sz > 0) {
            cnt = sz;
            first = c;
            break;
        }
    }
    string res = string(cnt, first);

    possible.erase(find(possible.begin(), possible.end(), first));
    auto allpossible = possible;

    while(res.size() < n) {

        if(possible.size() == 2) {
            int cur = possible[1];
            int cnt = 1;

            int sz = press(res + string(n, possible[0]));
            bool is0 = false;
            if(sz > res.size()) {
                cur = possible[0];
                cnt = sz-res.size();
                is0 = true;
            }

            res += string(cnt, cur);
            possible = allpossible;
            if(is0) {
                possible.erase(find(possible.begin(), possible.end(), cur));
            }
        } else {
            int sz = press(res + string(n, possible[0]) + res + string(n, possible[1]));
            if(sz == res.size()) {
                res += possible[2];
                possible = allpossible;
            } else {
                int id = 1;
                if(press(res + string(n, possible[0])) > res.size()) {
                    id = 0;
                }
                res += string(sz-res.size(), possible[id]);
                possible = allpossible;
                possible.erase(find(possible.begin(), possible.end(), possible[id]));
            }
        }
    }
    return res;
}

Compilation message (stderr)

combo.cpp:3:1: error: 'string' does not name a type
    3 | string guess_sequence(int n) {
      | ^~~~~~