Submission #908284

#TimeUsernameProblemLanguageResultExecution timeMemory
908284dragusanu_raresCombo (IOI18_combo)C++14
Compilation error
0 ms0 KiB
#include <iostream>
using namespace std;
string S="XABYBABABYYAYBA";
int it=0;
int press(string s){
    it++;
    int raspuns=0;
    for(int i=0;i<s.size();i++){
        int poz=0;
        while(poz<S.size()&&i+poz<s.size()&&s[i+poz]==S[poz]){
            poz++;
        }
        raspuns=max(raspuns,poz);
    }
    return raspuns;
}
string cunoscut;
char ch1,a,b,c;
inline void init(){
    if(ch1=='A'){
        a='B';
        b='X';
        c='Y';
    }
    else if(ch1=='B'){
        a='A';
        b='X';
        c='Y';
    }
    else if(ch1=='X'){
        a='A';
        b='B';
        c='Y';
    }
    else{
        a='A';
        b='B';
        c='X';
    }
}
inline void afla(){
    string guess=cunoscut+b+cunoscut+c+a+cunoscut+c+b+cunoscut+c+c;
    int x=press(guess)-cunoscut.size();
    if(x==0)cunoscut.push_back(a);
    else if(x==1)cunoscut.push_back(b);
    else cunoscut.push_back(c);
}
string guess_sequence(int n){
    if(n==1){
        if(press("X")==1)return "X";
        else if(press("Y")==1)return "Y";
        else if(press("A")==1)return "A";
        else return "B";
    }
    else{
        if(press("XY")>=1){
            if(press("X")==1)ch1='X';
            else ch1='Y';
        }
        else{
            if(press("A")==1)ch1='A';
            else ch1='B';
        }
        cunoscut=ch1;
        init();
        while(cunoscut.size()<n-1){
            afla();
        }
        if(press(cunoscut+a)==n)return cunoscut+a;
        else if(press(cunoscut+b)==n)return cunoscut+b;
        else return cunoscut+c;
    }
}

Compilation message (stderr)

combo.cpp: In function 'int press(std::string)':
combo.cpp:8:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
combo.cpp:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |         while(poz<S.size()&&i+poz<s.size()&&s[i+poz]==S[poz]){
      |               ~~~^~~~~~~~~
combo.cpp:10:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |         while(poz<S.size()&&i+poz<s.size()&&s[i+poz]==S[poz]){
      |                             ~~~~~^~~~~~~~~
combo.cpp: In function 'std::string guess_sequence(int)':
combo.cpp:66:30: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |         while(cunoscut.size()<n-1){
      |               ~~~~~~~~~~~~~~~^~~~
/usr/bin/ld: /tmp/ccFO6IZZ.o: in function `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)':
grader.cpp:(.text+0x0): multiple definition of `press(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)'; /tmp/ccjsIeiZ.o:combo.cpp:(.text+0xc0): first defined here
collect2: error: ld returned 1 exit status