Submission #772602

#TimeUsernameProblemLanguageResultExecution timeMemory
772602_martynasCombo (IOI18_combo)C++11
5 / 100
1 ms256 KiB
#include "combo.h"
#include <bits/stdc++.h>

using namespace std;

/*
Let known prefix be $ and first letter is A
press: $B + $XX + $XB + $XY
if this string returns |$|+1 then $ = $+'B'
else if this string returns |$|+2 then $ = $+'X'
else $ = $+'Y'
*/

string guess_sequence(int N) {
    string p = "AB";
    string S = "";
    vector<char> C = {'A', 'B', 'X', 'Y'};
    if(press(p)) {
        p = "A";
        if(press(p)) S = "A";
        else S = "B";
    }
    else {
        p = "X";
        if(press(p)) S = "X";
        else S = "Y";
    }
    for(int i = 0; i < N-2; i++) {
        p = "";
        string temp = "";
        for(char c : C) {
            if(c == S[0]) continue;
            if(p == "") {
                p = S; p += c;
                temp += c;
            }
            else if(p.size() == S.size()+1) {
                for(char cc : C) {
                    if(cc == S[0]) continue;
                    p += S; p += c; p += cc;
                }
                temp += c;
            }
            else {
                temp += c;
            }
        }
        int val = press(p);
        if(val == S.size()+1) {
            S += temp[0];
        }
        else if(val == S.size()+2) {
            S += temp[1];
        }
        else {
            S += temp[2];
        }
    }
    int cnt = 0;
    for(char c : C) {
        if(c == S[0]) continue;
        cnt++;
        if(cnt == 3) {
            S += c;
        }
        else {
            p = S; p += c;
            if(press(p) == N) {
                S += c; break;
            }
        }
    }
    return S;
}
/*

*/

Compilation message (stderr)

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