Submission #139904

#TimeUsernameProblemLanguageResultExecution timeMemory
139904vinceCombo (IOI18_combo)C++14
100 / 100
333 ms2048 KiB
#include "combo.h"
#include <stdio.h>
#include <iostream>
#include <string>
#include <assert.h>

using namespace std;

string C;

string guess_sequence(int N) 
{
    string S = "";
    int a = press("AX");

    if(a)
    {
        int x = press("A");
        if(x) S = "A", C = "BXY";
        else S = "X", C = "ABY";
    }
    else 
    {
        int x = press("B");
        if(x) S = "B", C = "AXY";
        else S = "Y", C = "ABX";
    }
    if(N == S.size())
        return S;

    while(S.size() != N-1)
    {
        string T = S + C.substr(0,1);
        for(int i = 0; i < 3; i++)
        {
            T += S + C.substr(1,1) + C.substr(i, 1);
        }
        int val = press(T);
        if(val == S.size()+1)
            S += C.substr(0,1);
        else if(val == S.size()+2)
            S += C.substr(1,1);   
        else
            S += C.substr(2,1);

        // cout << S << "\n";
        if(S.size() == N-1)
            break;
    }
    string T = S + C.substr(0,1) + S + C.substr(1,1);
    int x = press(T);
    
    if(x == N)
    {
        if(press(S + C.substr(0,1)) == N)
            return S + C.substr(0,1);
        else return S + C.substr(1,1);
    }
    else return S + C.substr(2,1);

    
    return S;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:28:10: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(N == S.size())
      |        ~~^~~~~~~~~~~
combo.cpp:31:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   31 |     while(S.size() != N-1)
      |           ~~~~~~~~~^~~~~~
combo.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if(val == S.size()+1)
      |            ~~~~^~~~~~~~~~~~~
combo.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         else if(val == S.size()+2)
      |                 ~~~~^~~~~~~~~~~~~
combo.cpp:47:21: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |         if(S.size() == N-1)
      |            ~~~~~~~~~^~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...