Submission #402746

#TimeUsernameProblemLanguageResultExecution timeMemory
402746luisgalanCombo (IOI18_combo)C++14
100 / 100
77 ms8644 KiB
#include<bits/stdc++.h>
#include "combo.h"
using namespace std;
#define debug(x) cerr << #x << " = " << (x) << endl

char chars[4] = {'A', 'B', 'X', 'Y'};
string guess_sequence(int N) {
    string res = "";
    char init;

    if (press("AB")) {
        init = press("A") ? 'A' : 'B';
    } else {
        init = press("X") ? 'X' : 'Y';
    }
    res += string(1, init);
    if (N == 1) {
        return res;
    }

    vector<char> others;
    vector<string> others_s;
    for (int i = 0; i < 4; i++) {
        if (chars[i] == init) continue;
        others.push_back(chars[i]);
        others_s.push_back(string(1, chars[i]));
    }

    while (res.size() + 1 < N) {
        string query = "";
        query += res + others_s[0] + others_s[0];
        query += res + others_s[0] + others_s[1];
        query += res + others_s[0] + others_s[2];
        query += res + others_s[1];
        debug(query);
        int delta_coins = press(query) - res.size();
        // debug(delta_coins);
        if (delta_coins == 2) {
            res += others_s[0];
        } else if (delta_coins == 1) {
            res += others_s[1];
        } else {
            res += others_s[2];
        }
        // debug(res);
    }
    if (press(res + others_s[0] + res + others_s[1]) > res.size()) {
        if (press(res + others_s[0]) > res.size()) {
            res += others_s[0];
        } else {
            res += others_s[1];
        }
    } else {
        res += others_s[2];
    }
    // debug(res);
    return res;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:29:27: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     while (res.size() + 1 < N) {
      |            ~~~~~~~~~~~~~~~^~~
combo.cpp:47:54: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     if (press(res + others_s[0] + res + others_s[1]) > res.size()) {
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
combo.cpp:48:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |         if (press(res + others_s[0]) > res.size()) {
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...