Submission #1340053

#TimeUsernameProblemLanguageResultExecution timeMemory
1340053omsincoconutCombo (IOI18_combo)C++17
30 / 100
6 ms484 KiB
#include <bits/stdc++.h>
#include "combo.h"

using namespace std;

string guess_sequence(int N) {
    string answer;

    // Step 1: find first character
    // 2 queries
    char first_char;
    if (press("AB") > 0) {
        if (press("A") > 0) first_char = 'A';
        else first_char = 'B';
    } else {
        if (press("X") > 0) first_char = 'X';
        else first_char = 'Y'; 
    }

    string nonfirst = "ABXY";
    nonfirst.erase(find(nonfirst.begin(), nonfirst.end(), first_char));

    answer.push_back(first_char);

    // Step 2: find second character
    // 3 queries
    for (int i = 0; i < 3; i++) {
        int query_result = press(answer + string(N, nonfirst[i]));
        answer = answer + string(query_result-(int)answer.size(), nonfirst[i]);
    }

    // Step 3: find other characters
    while (answer.size() < N) {
        string all_next = "ABXY";
        all_next.erase(find(all_next.begin(), all_next.end(), first_char));
        all_next.erase(find(all_next.begin(), all_next.end(), answer.back()));
        if (rand()%2) swap(all_next[0], all_next[1]);
        int query_result = press(answer + string(N, all_next[0]));
        if (query_result > (int)answer.size()) {
            answer = answer + string(query_result-(int)answer.size(), all_next[0]);
        } else {
            int query_result_2 = press(answer + string(N, all_next[1]));
            answer = answer + string(query_result_2-(int)answer.size(), all_next[1]);
        }
    }

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