Submission #668088

#TimeUsernameProblemLanguageResultExecution timeMemory
668088finn__Combo (IOI18_combo)C++17
100 / 100
57 ms512 KiB
#include <bits/stdc++.h>
#include "combo.h"
using namespace std;

char bin_search(string s)
{
    int j = press(s + 'A' + s + 'B');
    pair<char, char> left = (j > s.size() ? make_pair('A', 'B') : make_pair('X', 'Y'));

    j = press(s + left.first);
    if (j > s.size())
        return left.first;
    return left.second;
}

string guess_sequence(int n)
{
    string p;
    p.push_back(bin_search(""));

    if (n == 1)
        return p;

    vector<char> x;
    for (char c : {'A', 'B', 'X', 'Y'})
        if (c != p[0])
            x.push_back(c);

    for (size_t i = 1; i < n - 1; i++)
    {
        int j = press(p + x[0] +
                      p + x[1] + x[0] +
                      p + x[1] + x[1] +
                      p + x[1] + x[2]);

        if (j == p.size())
            p.push_back(x[2]);
        else if (j == p.size() + 1)
            p.push_back(x[0]);
        else
            p.push_back(x[1]);
    }

    p.push_back(bin_search(p));
    return p;
}

Compilation message (stderr)

combo.cpp: In function 'char bin_search(std::string)':
combo.cpp:8:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     pair<char, char> left = (j > s.size() ? make_pair('A', 'B') : make_pair('X', 'Y'));
      |                              ~~^~~~~~~~~~
combo.cpp:11:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     if (j > s.size())
      |         ~~^~~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:29:26: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |     for (size_t i = 1; i < n - 1; i++)
      |                        ~~^~~~~~~
combo.cpp:36:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         if (j == p.size())
      |             ~~^~~~~~~~~~~
combo.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |         else if (j == p.size() + 1)
      |                  ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...