Submission #636557

#TimeUsernameProblemLanguageResultExecution timeMemory
636557SonCombo (IOI18_combo)C++14
97 / 100
37 ms600 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("XY");
        if ( xy == 2 ){
            ans = "XY";
        } else if ( xy == 1 ) {
            xy = press("X");
            if ( xy == 1 ) ans = "X";
            else ans = "Y";
        } else {
            assert(1==2);
        }
    }
 
    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:36:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for ( int i = 0; i < V.size(); i++ ){
      |                      ~~^~~~~~~~~~
combo.cpp:34:9: warning: variable 'ch' set but not used [-Wunused-but-set-variable]
   34 |     int ch;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...