Submission #636559

#TimeUsernameProblemLanguageResultExecution timeMemory
636559SonCombo (IOI18_combo)C++14
100 / 100
30 ms640 KiB
#include <bits/stdc++.h>
#include "combo.h"
using namespace std;
 
string guess_sequence( int N ){
 
    vector < char > V;
    V.push_back('A');
    V.push_back('B');
    V.push_back('Y');
    V.push_back('X');
 
    string ans = "";
    int ab = press("AB");
    if ( ab == 2 ){
        ans = "AB";
    } else if ( ab == 1 ){
        ab = press("A");
        if ( ab == 1 ) ans = "A";
        else ans = "B";
    } else {
        int xy = press("X");
        if ( xy == 1 ) ans = "X";
        else ans = "Y";
    }
 
    int ch;
    vector < char > W;
    for ( int i = 0; i < V.size(); i++ ){
        if ( V[i] == ans[0] ){
            ch = i;
        } else {
            W.push_back(V[i]);
        }
    }
    while ( (int)(ans.size()) < N ){
        int prevN = (int)(ans.size());
        
        if ( N - prevN == 1 ){
            string t = ans + W[0];
            if ( press(t) == prevN + 1 ){
                ans += W[0];
            } else {
                t = ans + W[1];
                if ( press(t) == prevN + 1 ){
                    ans += W[1];
                } else {
                    ans += W[2];
                }
            }
        } else {
            string t = ans + W[0];
            t += ans + W[1]+ "" + W[0];
            t += ans + W[1]+ "" + W[1];
            t += ans + W[1]+ "" + W[2];
            int pt = press(t);
            if ( pt == prevN ){
                ans += W[2];
            } else if ( pt == prevN + 1 ){
                ans += W[0];
            } else {
                ans += W[1];
            }
        }
    }
    return ans;
}

Compilation message (stderr)

combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:29:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for ( int i = 0; i < V.size(); i++ ){
      |                      ~~^~~~~~~~~~
combo.cpp:27:9: warning: variable 'ch' set but not used [-Wunused-but-set-variable]
   27 |     int ch;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...